I downloaded and successfully got the AmazonSQS transport native integration sample (AmazonSQS transport native integration sample • Amazon SQS Transport Samples • Particular Docs)) running with json serialization using the existing package versions. NSB 7 is used by default.
(screengrab of existing package versions)
However, I have a hard dependency on NServiceBus 6 in our on-prem sites, so I need to run the native integration with NSB 6, not NSB 7.
When trying to run the native sqs integration with NSB 6, I’m getting this error from the framework when it goes to deserialize the native message:
NServiceBus.Transports.SQS.MessagePump Treating message with SQS Message Id cc38161d-a572-4a74-84c5-fec69ee7a39f as a poison message due to exception Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: e. Path '', line 0, position 0.
at Newtonsoft.Json.JsonTextReader.ParseValue()
at Newtonsoft.Json.JsonTextReader.Read()
at Newtonsoft.Json.JsonReader.ReadForType(JsonContract contract, Boolean hasConverter)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
at NServiceBus.Transports.SQS.MessagePump.<ProcessMessage>d__6.MoveNext() in C:\BuildAgent\work\a3a7604cdca0ab8\src\NServiceBus.AmazonSQS\MessagePump.cs:line 169. Moving to error queue.
These are the highest package versions I can use based on the NSB 6 constraint:
I’m dispatching the message using sqsClient like this:
var someNativeMessage = new SomeNativeMessage { ThisIsTheMessage = "Hello!" };
var messageSerialized = JsonConvert.SerializeObject(someNativeMessage);
var body = Convert.ToBase64String(Encoding.UTF8.GetBytes(messageSerialized));
var sendMessageRequest = new SendMessageRequest
{
QueueUrl = getQueueUrlResponse.QueueUrl,
MessageAttributes = messageAttributeValues,
MessageBody = body
};
await sqsClient.SendMessageAsync(sendMessageRequest).ConfigureAwait(false);
My guess is NSB 6 handles the deserialization of messages different than NSB 7 (and/or the NServiceBus.Newtonsoft.Json library does)? Maybe I need a custom serializer based on my NSB 6 constraints?
Thanks!
UPDATE 6/7: it seems that the message pump code of version 3.3.5 of NServiceBus.AmazonSQS assumes that all messages received by the pump are base64 encoded. You can see the same assumption being made in the latest version of the library here:
The message bodies that are being enqueue’d to SQS from sqsClient calls running in lambdas (aka, not an NSB endpoint) are not being base64 encoded, they’re just straight up json. I just learned this today. The above code that shows SendMessageAsync calls was just me trying to set up the code to test all of this.
Do all NServiceBus transport message pumps make the assumption that the transport’s native message body is base64 encoded?
If so, I won’t be able to use NSB native integration for SQS as the messages I need to consume will not be base64 encoded.