我可以使用以下代码成功发布消息:
using (IAdvancedBus bus = RabbitHutch.CreateBus("host=192.168.153.128:5672;username=user;password=pass").Advanced)
{
IExchange exchange = bus.ExchangeDeclare("milk.api", ExchangeType.Topic);
IQueue queue = bus.QueueDeclare("milkorderqueue");
IBinding binding = bus.Bind(exchange, queue, "#");
bus.Publish<MilkOrderRequest>(exchange, "#", true, new Message<MilkOrderRequest>(milkOrder));
}
return new HttpResponseMessage(System.Net.HttpStatusCode.OK);
当我的订户尝试提取消息时,EasyNetQ_Default_Error_Queue队列增加。这是侦听器的代码:
IBus bus = RabbitHutch.CreateBus(@"host=192.168.153.128:5672;username=user;password=pass");
bus.Subscribe<MilkOrderRequest>("my_subscription_id", message =>
{
Console.WriteLine($"Order recieved: {message.Milk}.");
}, config =>
{
config.WithQueueName("milkorderqueue");
});
我也尝试了以下失败的方法:
IAdvancedBus bus = RabbitHutch.CreateBus(@"host=192.168.153.128:5672;username=user;password=pass").Advanced;
IExchange exchange = bus.ExchangeDeclare("milkshop.subscriber", ExchangeType.Topic);
IQueue queue = bus.QueueDeclare("milkorderqueue");
bus.Bind(exchange, queue, "#");
bus.Consume<MilkOrderRequest>(queue, (message, info) =>
{
Console.WriteLine($"Order recieved: {message.Body.Milk}.");
});
我无法在Google上找到有关该异常的答案:
messageType不能为null
这是完整的消息:
{
"RoutingKey":"#",
"Exchange":"milk.api",
"Queue":"milkorderqueue",
"Exception":"System.AggregateException: One or more errors occurred. (messageType must not be null\r\nParameter name: messageType) ---> System.ArgumentNullException: messageType must not be null\r\nParameter name: messageType\r\n at EasyNetQ.Preconditions.CheckNotNull[T](T value, String name, String message)\r\n at EasyNetQ.Preconditions.CheckNotNull[T](T value, String name)\r\n at EasyNetQ.MessageFactory.CreateInstance(Type messageType, Object body, MessageProperties properties)\r\n at EasyNetQ.RabbitAdvancedBus.<>c__DisplayClass17_0.<Consume>b__0(Byte[] body, MessageProperties properties, MessageReceivedInfo messageReceivedInfo)\r\n at EasyNetQ.Consumer.HandlerRunner.InvokeUserMessageHandler(ConsumerExecutionContext context)\r\n --- End of inner exception stack trace ---\r\n---> (Inner Exception #0) System.ArgumentNullException: messageType must not be null\r\nParameter name: messageType\r\n at EasyNetQ.Preconditions.CheckNotNull[T](T value, String name, String message)\r\n at EasyNetQ.Preconditions.CheckNotNull[T](T value, String name)\r\n at EasyNetQ.MessageFactory.CreateInstance(Type messageType, Object body, MessageProperties properties)\r\n at EasyNetQ.RabbitAdvancedBus.<>c__DisplayClass17_0.<Consume>b__0(Byte[] body, MessageProperties properties, MessageReceivedInfo messageReceivedInfo)\r\n at EasyNetQ.Consumer.HandlerRunner.InvokeUserMessageHandler(ConsumerExecutionContext context)<---\r\n",
"Message":"{\"Milk\":\"semi-skimmed\"}",
"DateTime":"2018-06-01T11:01:11.645241Z",
"BasicProperties":{
"ContentType":null,
"ContentEncoding":null,
"Headers":{
},
"DeliveryMode":0,
"Priority":0,
"CorrelationId":"fe1561c1-4c7c-4489-857e-b664f27a5e5f",
"ReplyTo":null,
"Expiration":null,
"MessageId":null,
"Timestamp":0,
"Type":"Milkshop.Common.MilkOrderRequest:Milkshop.Common",
"UserId":null,
"AppId":null,
"ClusterId":null,
"ContentTypePresent":false,
"ContentEncodingPresent":false,
"HeadersPresent":true,
"DeliveryModePresent":false,
"PriorityPresent":false,
"CorrelationIdPresent":true,
"ReplyToPresent":false,
"ExpirationPresent":false,
"MessageIdPresent":false,
"TimestampPresent":false,
"TypePresent":true,
"UserIdPresent":false,
"AppIdPresent":false,
"ClusterIdPresent":false
}
}
我在.Net Core应用程序上使用EasynetQ版本3.0.0
最佳答案
发现错误。我的API项目和控制台应用程序使用的是EasynetQ nuget软件包的不同版本。一个是2.33,另一个是3.0.0。