Native Integration with Azure Storage Queues Transport

Component: Azure Storage Queues Transport
NuGet Package NServiceBus.Transport.AzureStorageQueues (11-pre)
Target NServiceBus Version: 8.x
This page targets a pre-release version and is subject to change prior to the final release.

Prerequisites

Ensure an instance of the Azure Storage Emulator or Azurite is running.

Azure Storage Queues transport

This sample uses the Azure Storage Queues transport.

Code walk-through

This sample shows a simple two-endpoint scenario.

  • NativeSender sends a NativeMessage message to Receiver
  • Receiver receiving and printing out the contents of the received message.

Sending a native message

NativeSender creates and sends a queue message with a JSON serialized NativeMessage payload.

var nativeMessage = new NativeMessage
{
    Content = $"Hello from native sender @ {DateTimeOffset.Now}"
};

var serializedMessage = JsonConvert.SerializeObject(nativeMessage);

await queueClient.SendMessageAsync(serializedMessage).ConfigureAwait(false);

Receiving a native message

To process a native message, the native QueueMessage has to be adapted to the NServiceBus MessageWrapper first. To accomplish this, a custom envelope unwrapper must be registered to provide the following:

  1. Message ID to associate with the incoming message
  2. Serialized message payload as a byte array
  3. Determine the native message type and assign it as an NServiceBus header
transport.MessageUnwrapper = message => new MessageWrapper
{
    Id = message.MessageId,
    Body = message.Body.ToArray(),
    Headers = new Dictionary<string, string>
    {
        { Headers.EnclosedMessageTypes, typeof(NativeMessage).FullName }
    }
};
Message type could be determined dynamically by reading the payload if different message types are sent natively.

Related Articles


Last modified