Native integration

Component: Amazon SQS Transport
NuGet Package NServiceBus.AmazonSQS (5.3)
Target NServiceBus Version: 7.x

This document describes how to consume messages from and send messages to non-NServiceBus endpoints via Amazon SQS in integration scenarios.

Accessing the native Amazon SQS message

It is sometimes useful to access the native Amazon SQS message from behaviors and handlers. When a message is received, the transport adds the native message, an instance of Amazon.SQS.Model.Message, to the message processing context. For example, the native message may be accessed from a pipeline behavior:

class AccessToAmazonSqsNativeMessage : Behavior<IIncomingContext>
{
    public override Task Invoke(IIncomingContext context, Func<Task> next)
    {
        // get the native Amazon SQS message
        var message = context.Extensions.Get<Message>();

        //do something useful

        return next();
    }
}

Message type detection

NServiceBus requires the the message type to be available as part of the message metadata to process a message successfully.

During message processing, the SQS transport inspects the native message attributes for an attribute with the name MessageTypeFullName and a value representing a full type name (i.ex Sales.OrderAccepted). If the attribute is present, the message is treated as a native message, and the body is deserialized into the target type represented by MessageTypeFullName.

The native message body is loaded from the configured S3 bucket when the message attribute contains an attribute with the key S3BodyKey and the value representing an S3 object key, including the necessary prefix as configured by the receiving endpoint.

Whenever the native message needs to be copied for moving messages to the error queue, auditing or delayed retries purposes, the native message is converted into the transport's internal structure. The MessageTypeFullName and S3BodyKey headers are moved from the native message attributes into the headers collection. All other available message attributes from the original native message are copied over into the newly formed native message.

Samples


Last modified