Consume Native SQS message then publish NServiceBus message - is this possible?

I’ve been through the docs and numerous Github issues but I’m still not sure if what I want to do is possible with NServiceBus + SQS transport.

Problem: I want to have an endpoint that will consume a native message from SQS. The message will be in JSON but not base64-encoded. I then want my endpoint to handle the message, do stuff, then publish a proper NServiceBus message for my other endpoints to consume.

I’m using the following code for my endpoint’s serialization:

    var serializer =  endpointConfiguration.UseSerialization<NewtonsoftJsonSerializer>();
    serializer.Settings(new JsonSerializerSettings
    {
        TypeNameHandling = TypeNameHandling.Auto
    });

I tested this by adding a message in SQS and adding a $type property that contains the fully qualified class name of the message.

I get the error:

Newtonsoft.Json.JsonSerializationException: Type specified in JSON '<FullClassName>' was not resolved. Path '$type', line 2, position 55.

My questions are:

  1. Why can’t NServiceBus successfully deserialize the message given there’s a $type property?
  2. Is it possible for my endpoint to publish a proper NServiceBus message if I configure the serializer to use TypeNameHandling.Auto

Hi Gian,

Is it possible to share some more of your code? Specifically, are you attempting to do this within a behaviour as per our native integration sample?

NServiceBus tries to determine the message type via a few method, the fist is via the default message detection from the NServiceBus.AmazonSQS.Headers header.

In your case, this header does not exist so NServiceBus will fall back to the MessageTypeFullName header. Since you only have the $type property in the JSON body, this will also not apply.

Since you provide the $type property, NServiceBus will treat your message as a native message and it should be capable of deserializing the message.

Can you also share the full value of your typename you are specifying in $type? It needs to be fully qualified including the assembly name.