Brokered Message Creation

Component: Azure Service Bus Transport
NuGet Package NServiceBus.Azure.Transports.WindowsAzureServiceBus (8-pre)
Target NServiceBus Version: 6.x
This page targets a pre-release version and is subject to change prior to the final release.

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.

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.

endpointConfiguration.UseSerialization<XmlSerializer>();

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

Required Headers

For a native message to be processed, NServiceBus endpoints using the Azure Service Bus transport require the following headers. These headers need to be stored as BrokeredMessage properties.

In native integration scenarios it is not always possible, or desirable, to modify the headers of the brokered message at the sending end. If this is the case, the receiving end can also add the required headers to the message by registering an incoming Message Mutators or via a Pipeline Behavior.

Related Articles


Last modified