gpt4 book ai didi

azure - 由于 Newtonsoft JsonReaderException,随机出现 NServiceBus MessageDeserializationException

转载 作者:行者123 更新时间:2023-12-02 07:54:39 28 4
gpt4 key购买 nike

反序列化命令时,我们遇到随机异常。我们有一个仅发送 API,可将消息放入队列中。尝试使用消息但失败。无论消息类型如何,它都会随机发生。有时后端可以反序列化消息。我们将 NServiceBus 设置为使用 NewtonSoft.Json(API 使用 12.0.3,后端使用 12.0.1)并使用默认设置。由于我们使用 ICommand 声明命令,因此我们不使用不显眼的模式。我们使用 Azure ServiceBus 作为传输。

最令人不安的是:我们的暂存环境(BETA)中拥有几乎完全相同的基础设施,并且一切正常。当我们在两个环境(测试版和生产环境)上重现相同的消息时,可以在测试版上使用相同的数据对消息进行反序列化,而在生产环境中则不能。所有 header 和正文数据都是相同的,甚至包含的消息类型也是如此。两种环境都使用相同(二进制相同)的二进制文件。两种环境都在 Azure 上配置几乎相同的应用程序服务上运行(例如 net core 3.1、win 64 位)。

{
"AmqpMessage": null,
"Body": "{\"Email\":\"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cdbba2aba4a1fbf4f5fff48dafafbeaca4a1a4e3aea2a0" rel="noreferrer noopener nofollow">[email protected]</a>\",\"AccountantId\":{\"Value\":\"75f61737-b9e8-40a3-a1c4-23d7bd61c527\"}}",
"MessageId": "d829e8ce-261f-4033-a294-f279c0390851",
"PartitionKey": null,
"TransactionPartitionKey": null,
"SessionId": null,
"ReplyToSessionId": null,
"TimeToLive": "10675199.02:48:05.4775807",
"CorrelationId": "2ca22dd7-396b-4950-acb6-ad4800ac9d65",
"Subject": null,
"To": null,
"ContentType": "application/json",
"ReplyTo": null,
"ScheduledEnqueueTime": "0001-01-01T00:00:00+00:00",
"ApplicationProperties": {
"NServiceBus.Transport.Encoding": "application/octect-stream",
"NServiceBus.MessageId": "2ca22dd7-396b-4950-acb6-ad4800ac9d65",
"NServiceBus.MessageIntent": "Send",
"NServiceBus.ConversationId": "97743453-c3ac-4e08-a1df-ad4800ac9d65",
"NServiceBus.CorrelationId": "2ca22dd7-396b-4950-acb6-ad4800ac9d65",
"NServiceBus.OriginatingMachine": "dw1sdwk00002R",
"NServiceBus.OriginatingEndpoint": "AwarenessCenter.Api",
"$.diagnostics.originating.hostid": "a5a720d14ccabd7a8ba708f5bc79b2a3",
"NServiceBus.ContentType": "application/json",
"NServiceBus.EnclosedMessageTypes": "AwarenessCenter.Domain.Users.Registration.InviteUserCommand, AwarenessCenter.Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
"NServiceBus.Version": "7.4.4",
"NServiceBus.TimeSent": "2021-06-15 10:28:28:288468 Z",
"Diagnostic-Id": "00-1d6433cf14ae654a84e290f66d5faf25-3b4885ae29c8fc4f-00",
"NServiceBus.ExceptionInfo.ExceptionType": "NServiceBus.MessageDeserializationException",
"NServiceBus.ExceptionInfo.InnerExceptionType": "Newtonsoft.Json.JsonReaderException",
"NServiceBus.ExceptionInfo.HelpLink": null,
"NServiceBus.ExceptionInfo.Message": "An error occurred while attempting to extract logical messages from incoming physical message 2ca22dd7-396b-4950-acb6-ad4800ac9d65",
"NServiceBus.ExceptionInfo.Source": "NServiceBus.Core",
"NServiceBus.ExceptionInfo.StackTrace": "NServiceBus.MessageDeserializationException: An error occurred while attempting to extract logical messages from incoming physical message 2ca22dd7-396b-4950-acb6-ad4800ac9d65\r\n ---> Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: {. Path 'AccountantId', line 1, position 50.\r\n at Newtonsoft.Json.JsonTextReader.ReadStringValue(ReadType readType)\r\n at Newtonsoft.Json.JsonTextReader.ReadAsString()\r\n at Newtonsoft.Json.JsonReader.ReadForType(JsonContract contract, Boolean hasConverter)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)\r\n at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)\r\n at NServiceBus.Newtonsoft.Json.JsonMessageSerializer.ReadObject(Stream stream, Boolean isArrayStream, Type type)\r\n at NServiceBus.Newtonsoft.Json.JsonMessageSerializer.DeserializeMultipleMessageTypes(Stream stream, IList`1 messageTypes, Boolean isArrayStream)\r\n at NServiceBus.Newtonsoft.Json.JsonMessageSerializer.Deserialize(Stream stream, IList`1 messageTypes)\r\n at NServiceBus.DeserializeMessageConnector.Extract(IncomingMessage physicalMessage) in /_/src/NServiceBus.Core/Pipeline/Incoming/DeserializeMessageConnector.cs:line 119\r\n at NServiceBus.DeserializeMessageConnector.ExtractWithExceptionHandling(IncomingMessage message) in /_/src/NServiceBus.Core/Pipeline/Incoming/DeserializeMessageConnector.cs:line 53\r\n --- End of inner exception stack trace ---\r\n at NServiceBus.DeserializeMessageConnector.ExtractWithExceptionHandling(IncomingMessage message) in /_/src/NServiceBus.Core/Pipeline/Incoming/DeserializeMessageConnector.cs:line 53\r\n at NServiceBus.DeserializeMessageConnector.Invoke(IIncomingPhysicalMessageContext context, Func`2 stage) in /_/src/NServiceBus.Core/Pipeline/Incoming/DeserializeMessageConnector.cs:line 29\r\n at NServiceBus.InvokeAuditPipelineBehavior.Invoke(IIncomingPhysicalMessageContext context, Func`2 next) in /_/src/NServiceBus.Core/Audit/InvokeAuditPipelineBehavior.cs:line 27\r\n at NServiceBus.ProcessingStatisticsBehavior.Invoke(IIncomingPhysicalMessageContext context, Func`2 next) in /_/src/NServiceBus.Core/Performance/Statistics/ProcessingStatisticsBehavior.cs:line 32\r\n at NServiceBus.TransportReceiveToPhysicalMessageConnector.Invoke(ITransportReceiveContext context, Func`2 next) in /_/src/NServiceBus.Core/Pipeline/Incoming/TransportReceiveToPhysicalMessageConnector.cs:line 61\r\n at NServiceBus.MainPipelineExecutor.Invoke(MessageContext messageContext) in /_/src/NServiceBus.Core/Pipeline/MainPipelineExecutor.cs:line 50\r\n at NServiceBus.Transport.AzureServiceBus.MessagePump.InnerProcessMessage(Task`1 receiveTask)",
"NServiceBus.TimeOfFailure": "2021-06-15 10:28:28:346039 Z",
"NServiceBus.ExceptionInfo.Data.Message ID": "2ca22dd7-396b-4950-acb6-ad4800ac9d65",
"NServiceBus.ExceptionInfo.Data.Transport message ID": "b6c3a3cf-84bf-4235-8551-35a1daf4bc5d",
"NServiceBus.FailedQ": "AwarenessCenter.Backend",
"NServiceBus.ProcessingMachine": "dw1sdwk00002R",
"NServiceBus.ProcessingEndpoint": "AwarenessCenter.Backend",
"$.diagnostics.hostid": "f0377aabcaf4cc26d4afb3e60b704550",
"$.diagnostics.hostdisplayname": "dw1sdwk00002R"
},
"LockToken": "00000000-0000-0000-0000-000000000000",
"DeliveryCount": 0,
"LockedUntil": "0001-01-01T00:00:00+00:00",
"SequenceNumber": 541,
"DeadLetterSource": null,
"PartitionId": 0,
"EnqueuedSequenceNumber": 0,
"EnqueuedTime": "2021-06-15T10:28:28.396+00:00",
"LockTokenGuid": "00000000-0000-0000-0000-000000000000",
"ExpiresAt": "9999-12-31T23:59:59.9999999+00:00",
"DeadLetterReason": null,
"DeadLetterErrorDescription": null
}

最佳答案

我怀疑消息的序列化未正确完成,或者序列化和反序列化的类型不相同。 NServiceBus 抛出的异常正在暗示(有关详细信息,请参阅 NServiceBus.ExceptionInfo.StackTrace header 。具体来说

An error occurred while attempting to extract logical messages from incoming physical message 2ca22dd7-396b-4950-acb6-ad4800ac9d65\r\n ---> Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: {. Path 'AccountantId', line 1, position 50

基于序列化的有效负载

"{"Email":"[email protected]","AccountantId":{"Value":"75f61737-b9e8-40a3-a1c4-23d7bd61c527"}}"

看起来 AccountantId 不是一个简单类型,而是一个嵌套类型,因为 JSON 转换为

{
"Email":"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a0d6cfc6c9cc9699989299e0c2c2d3c1c9ccc98ec3cfcd" rel="noreferrer noopener nofollow">[email protected]</a>",
"AccountantId":
{
"Value":"75f61737-b9e8-40a3-a1c4-23d7bd61c527"
}
}

我怀疑接收方期望看到以下类型的消息

class SomeContract
{
public string Email { get; set; }
public Guid AccountantId { get; set; }
}

关于azure - 由于 Newtonsoft JsonReaderException,随机出现 NServiceBus MessageDeserializationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67985671/

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