Azure Service Bus Transport

Project Hosting
NuGet NServiceBus.Azure.Transports.WindowsAzureServiceBus (5.x)
Target NServiceBus Version: 4.x
Standard support for version 4.x of NServiceBus has expired. For more information see our Support Policy.

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.

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:

configure.UseTransport<AzureServiceBus>();

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 App.Config

<configuration>
  <connectionStrings>
     <add name="NServiceBus/Transport"
          connectionString="Endpoint=sb://{namespace}.servicebus.windows.net/;SharedSecretIssuer=owner;SharedSecretValue={key}" />
  </connectionStrings>
</configuration>

Samples

Related Articles


Last modified