Azure Service Bus Transport

Component: Azure Service Bus Transport
NuGet Package NServiceBus.Azure.Transports.WindowsAzureServiceBus (7.x)
Target NServiceBus Version: 6.x


An environment variable named AzureServiceBus.ConnectionString with the connection string for the Azure Service Bus namespace.

Azure Service Bus Transport

This sample utilizes the Azure Service Bus Transport.

Code walk-through

This sample shows a simple two endpoint scenario.

  • Endpoint1 sends a Message1 message to Endpoint1.
  • Endpoint2 replies to Endpoint1 with a Message2.

Azure Service Bus configuration

The Server endpoint is configured to use the Azure Storage persistence in two locations.

var endpointConfiguration = new EndpointConfiguration("Samples.Azure.ServiceBus.Endpoint1");
var transport = endpointConfiguration.UseTransport<AzureServiceBusTransport>();
var connectionString = Environment.GetEnvironmentVariable("AzureServiceBus.ConnectionString");
if (string.IsNullOrWhiteSpace(connectionString))
    throw new Exception("Could not read the 'AzureServiceBus.ConnectionString' environment variable. Check the sample prerequisites.");

Some things to note:

  • The use of the SamplesAzureServiceBusConnection environment variable mentioned above.

Viewing message in-flight

The following queues for the two endpoints can be seen in the Azure Portal or a 3rd party tool:

  • error

Related Articles

Last modified