AI agents: use the documentation index at llms.txt to locate machine-readable pages. This section is indexed by https://docs.particular.net/samples/llms.txt. The markdown version of this page is served as plain text. An MCP server at /mcp serves the same content via the search_docs and read_doc tools; it is read-only and needs no credentials. Markdown versions of documentation pages are available by appending .md to the page URL. Directory URLs use index.md. They are served as text/plain because some retrieval backends reject text/markdown.

Azure Storage Queues transport native integration sample

Target Version:
NServiceBus 10.x

Prerequisites

Ensure an instance of the Azurite Storage Emulator 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
{
    NativeMessageId = Guid.NewGuid(),
    Content = $"Hello from native sender @ {DateTimeOffset.Now}"
};

var serializedMessage = JsonSerializer.Serialize(nativeMessage);

await queueClient.SendMessageAsync(serializedMessage);

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 =>
    message.MessageText.Contains("NativeMessageId") &&
    message.MessageText.Contains("Content")
    ? new MessageWrapper
    {
        Id = message.MessageId,
        Body = message.Body.ToArray(),
        Headers = new Dictionary<string, string>
        {
            { Headers.EnclosedMessageTypes, typeof(NativeMessage).FullName }
        }
    }
    : null; // not a raw native message - allow the framework to deal with it

Related Articles