gpt4 book ai didi

c# - EasynetQ 总线。订阅未触发 - 抛出 "messageType must not be null"

转载 作者:行者123 更新时间:2023-11-30 23:02:05 26 4
gpt4 key购买 nike

我可以使用以下代码成功发布消息:

        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 must not be 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。

关于c# - EasynetQ 总线。订阅未触发 - 抛出 "messageType must not be null",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50648956/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com