我遇到了NSB恢复到Xml Serializer的问题,因为没有明显的理由在尝试反序列化消息时出现错误。下面是日志的摘录,你可以看到一些来自与Json相同的来源,然后是突然的XML!
2018-06-05 08:51:36.924 INFO Stockly.Services.Messaging.Common.Extensions.MessageBodyWriter序列化消息正文: 2018-06-05 08:51:37.026 INFO 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 INFO Stockly.Services.Messaging.Common.Extensions.MessageBodyWriter序列化消息正文: 2018-06-05 08:51:38.728 INFO 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 INFO 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 INFO Stockly.Services.Messaging.Common.Extensions.MessageBodyWriter BinanceRPXBTC15 2018-06-05 08:51:39.824 ERROR NServiceBus.RecoverabilityExecutor移动消息' f095da8a-e830-4873-8fa0-a8f200719739'到错误队列'错误'因为处理因异常而失败: NServiceBus.MessageDeserializationException:尝试从传入的物理消息中提取逻辑消息时发生错误f095da8a-e830-4873-8fa0-a8f200719739 ---> Newtonsoft.Json.JsonReaderException:解析值时遇到意外的字符:<。路径'',第0行,第0位。 在Newtonsoft.Json.JsonTextReader.ParseValue()
这是配置。
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;
}
知道为什么会发生这种情况以及如何阻止这种情况发生?
P.S。目前我正在使用LearningTransport。
答案 0 :(得分:0)
事实证明,这是以前测试运行留下的一些消息,这些消息仍然使用xml作为序列化格式。清除输入队列即可解决问题。
更多详细信息:https://github.com/Particular/NServiceBus/issues/5181#issuecomment-396141572