【问题标题】:NServiceBus Reverts back to XmlSerilizer for no reasonNServiceBus 无缘无故恢复到 XmlSerilizer
【发布时间】:2018-07-13 14:32:00
【问题描述】:

我在 NSB 无明显原因恢复到 Xml 序列化程序时遇到问题,这在尝试反序列化消息时显然会导致错误。下面是日志的摘录,你可以看到一些来自与 Json 相同的来源,然后突然变成了 XML!

2018-06-05 08:51:36.924 INFO Stockly.Services.Messaging.Common.Extensions.MessageBodyWriter 序列化消息正文: 2018-06-05 08:51:37.026 信息 Stockly.Services.Messaging.Common.Extensions.MessageBodyWriter {"Exchange":"Binance","Symbol":"SYSBTC","MinutesPerCandle":15} 2018-06-05 08:51:38.505 INFO Stockly.Services.QuoteService.QuoteHandler 收到 SYSBTC 的报价请求并检索 1000 支蜡烛 2018-06-05 08:51:38.725 信息 Stockly.Services.Messaging.Common.Extensions.MessageBodyWriter 序列化消息正文: 2018-06-05 08:51:38.728 信息 Stockly.Services.Messaging.Common.Extensions.MessageBodyWriter {"Exchange":"Binance","Symbol":"DASHBTC","MinutesPerCandle":15} 2018-06-05 08:51:39.194 INFO Stockly.Services.QuoteService.QuoteHandler 收到 DASHBTC 的报价请求并检索 1000 支蜡烛 2018-06-05 08:51:39.228 INFO Stockly.Services.Messaging.Common.Extensions.MessageBodyWriter 序列化消息正文: 2018-06-05 08:51:39.230 信息 Stockly.Services.Messaging.Common.Extensions.MessageBodyWriter {"Exchange":"Binance","Symbol":"ENJBTC","MinutesPerCandle":15} 2018-06-05 08:51:39.715 INFO Stockly.Services.QuoteService.QuoteHandler 收到 ENJBTC 报价请求并检索 1000 支蜡烛 2018-06-05 08:51:39.774 INFO Stockly.Services.Messaging.Common.Extensions.MessageBodyWriter 序列化消息正文: 2018-06-05 08:51:39.777 信息 Stockly.Services.Messaging.Common.Extensions.MessageBodyWriter BinanceRPXBTC15 2018-06-05 08:51:39.824 错误 NServiceBus.RecoverabilityExecutor 将消息“f095da8a-e830-4873-8fa0-a8f200719739”移动到错误队列“错误”,因为处理因异常而失败: NServiceBus.MessageDeserializationException:尝试从传入的物理消息 f095da8a-e830-4873-8fa0-a8f200719739 中提取逻辑消息时发生错误 ---> Newtonsoft.Json.JsonReaderException:解析值时遇到意外字符:

这是配置。

public static EndpointConfiguration ConfigureSerialization(this EndpointConfiguration endpointConfiguration)
        {
            var serialization = endpointConfiguration.UseSerialization<NewtonsoftSerializer>();
            serialization.ContentTypeKey("NewtonsoftJson");
            var settings = new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.Auto,
                Converters =
                    {
                        new IsoDateTimeConverter
                        {
                            DateTimeStyles = DateTimeStyles.RoundtripKind
                        }
                    }
            };

            serialization.Settings(settings);
            endpointConfiguration.RegisterMessageMutator(new MessageBodyWriter());

            var externalNewtonsoftJson = endpointConfiguration.AddDeserializer<NewtonsoftSerializer>();
            externalNewtonsoftJson.ContentTypeKey("NewtonsoftJson");

            return endpointConfiguration;
        }

知道为什么会发生这种情况以及如何阻止这种情况发生吗?

附:目前我正在使用 LearningTransport。

【问题讨论】:

  • 不确定为什么要覆盖内容类型键。您的发送端点是否配置正确?如果您使用相同的内容类型键但不同的设置注册了两次序列化程序,这也很奇怪。

标签: nservicebus


【解决方案1】:

这原来是之前的测试运行留下的一些仍然使用 xml 作为序列化格式的消息。清除输入队列解决了这个问题。

更多详情:https://github.com/Particular/NServiceBus/issues/5181#issuecomment-396141572

【讨论】:

    猜你喜欢
    • 2011-10-16
    • 2017-04-11
    • 1970-01-01
    • 2023-04-03
    • 1970-01-01
    • 2018-06-14
    • 2021-02-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多