Brokered Message Creation

This page refers to the legacy Azure Service Bus transport that uses the WindowsAzure.ServiceBus NuGet package. This package is currently on extended support until May 2022, after which it will be out of support according to the support policy. All users should migrate to the Azure Service Bus transport transport.

This document describes how to modify brokered message creation logic in order to set up a native integration between NServiceBus and non-NServiceBus endpoints.

BrokeredMessage conventions

Brokered Message body format

The Azure Service Bus API allows the construction of a BrokeredMessage body from a stream or an object that will then be serialized into a byte array.

Both the sender (native or NServiceBus) and the receiver must have a consistent convention for the communication the message body.

By default, the BrokeredMessage body is assumed to be a byte array to remain backward compatible with previous versions of the transport. It is recommended that the body can be retrieved using Stream for new implementations, as it incurs less of a memory overhead during serialization. It is especially useful for scenarios, such as native integration, as most non .NET ASB SDK's only support the Stream body format.

The SupportedBrokeredMessageBodyTypes.Stream body format is recommended, but this mode is currently NOT compatible with ServiceControl. A ServiceControl transport adapter is required in order to leverage both.

Body format detection

The NServiceBus.Transport.Encoding header can optionally be used to control the transport's body format detection, if it is not explicitly configured. The value must be set to application/octet-stream.

Brokered Message content serialization

The Azure Service Bus transport is using the JSON serializer by default. Therefore, the message sent by a native sender needs to be valid JSON.

    "Content": "Hello from native sender",
    "SentOnUtc": "2015-10-27T20:47:27.4682716Z" 

If the application uses a different serialization for message content, then it can be configured as follows.


If the message content is in an unsupported or proprietary format, then the application will have to provide a custom serializer

Message type detection

The native message must allow NServiceBus to detect the message type either via the headers or the message payload.

Related Articles

Last modified