从一个端点向另一个端点发送命令时获取MessageDeserializationException

问题描述

我试图将命令从一个端点发送到另一个端点,但是消息被丢弃在错误队列中,并且发生此错误

Could not determine message type from message header.......

NServiceBus.MessageDeserializationException: An error occurred while attempting to extract logical messages from incoming physical message 532951ea-8bcd-4ddb-9ba5-ac4c00d5c74e
 ---> System.Exception: Could not find metadata for 'Newtonsoft.Json.Linq.JObject'.

这是我的命令

  public class PolicyCreationRequested: ICommand
    {
        public Guid Id { get; set; }
        public string Text { get; set; }
    }

这是命令发送

public async Task Handle(PaymentRequested paymentRequested,IMessageHandlerContext context)
        {
            var policyCreationRequested = new PolicyCreationRequested{ Id = Guid.NewGuid(),Text = "Hello From Different Service"};
            await context.Send ("---Endpoint Name---",policyCreationRequested).ConfigureAwait (false);
            await _paymentService.CreateRequest(paymentRequested.PaymentRequest);
        }

这是Nservicebus配置(两个服务都相同)我使用扩展方法

.UseNServiceBus(configuration =>
                {
                    var applicationConfiguration =
                        ApplicationConfigurationBuilder.GetConfiguration();

                    return new EndpointConfiguration("---Endpoint Name---")
                        .UseRabbitMQTransport(configuration =>
                            configuration
                                .ConnectionString(applicationConfiguration["NServiceBus:RabbitMqTransport:ConnectionString"]))
                        .UseInMemoryPersistence()
                        .UseNewtonsoftSerialization(configuration =>
                            configuration
                                .UseMessagePackReaderAndWriterCreators())
                })

我将Newtonsoft序列化与MessagePack读取器和写入器一起使用。此实现适用于相同的端点情况,但是当我尝试在不同端点之间发送命令时,会发生此错误。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)