Azure Service Bus Transport (Legacy)

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.

Azure Service Bus (ASB) is a messaging service hosted on the Azure platform, that allows for exchanging messages between various applications in a loosely coupled fashion. ASB Queues offer "First In, First Out" (FIFO) guaranteed message delivery, and support a range of standard protocols (REST, AMQP, WS*) and APIs (to put messages on and pull messages off the queue). ASB Topics deliver messages to multiple subscribers and facilitate use of the fan-out pattern to deliver messages to downstream systems.

NServiceBus is an abstraction over ASB. It takes advantage of ASB's built-in features, such as message batching and deferred messages. It also provides a higher-level, convenient API for programmers on top of ASB.

Publish/Subscribe and Timeouts (including message deferral) are supported natively by the ASB transport and do not require NServiceBus persistence.
  • The main advantage of ASB is that it offers a highly reliable and low latency remote messaging infrastructure. A single message can be up to 256 KB in size (1 MB for Premium), and a queue can store many messages at once, up to 5 GB size in total. Furthermore, it is capable of emulating local transactions using its queue peek-lock mechanism.
  • The main disadvantage of ASB is its dependency on TCP (for low latency), which may require opening outbound ports on the firewall. Additionally, in some systems the price for the service (at the per message level) may be significant.
As part of the Azure support for NServiceBus, one can choose between two transports provided by the Azure platform: Azure Storage Queues and Azure Service Bus. Each of them has different features, capabilities, and usage characteristics. A detailed comparison and discussion of when to select which is beyond the scope of this document. To help decide which option best suits the application's needs, refer to the Azure Queues and Azure Service Bus Queues - Compared and Contrasted article.

When considering an Azure Transport it is important to consider the transaction guarantees that that service provides.

Transport at a glance

TransactionsNone, ReceiveOnly, SendsWithAtomicReceive
Large message bodiesvia higher tier (e.g. Premium) or data bus
Scale-outCompeting consumer
Scripted DeploymentNot supported
Native integrationSupported

Enabling the Transport

When creating the namespace at the Azure portal, choose Standard or Premium Messaging Tier for Azure Service Bus.

Then at configuration time set ASB as the transport:

var transport = endpointConfiguration.UseTransport<AzureServiceBusTransport>();

Setting the Connection String

For more details on setting up connection strings and securing them, refer to the Configuration Connection Strings and the Securing Credentials articles.

To set the connection string use the following:

Via Code

var transport = endpointConfiguration.UseTransport<AzureServiceBusTransport>();

Via App.Config

     <add name="NServiceBus/Transport"
          connectionString="Endpoint=sb://{namespace};SharedSecretIssuer=owner;SharedSecretValue={key}" />


Related Articles

Last modified