Azure Service Bus Transport

This page refers to the legacy Azure Service Bus transport, which is rendered obsolete by the Azure Service Bus transport built to target both .NET Framework and .NET Core. All new projects should use the new Azure Service Bus transport.

Prerequisites

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 Endpoint2.
  • 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 busConfiguration = new BusConfiguration();
busConfiguration.EndpointName("Samples.Azure.ServiceBus.Endpoint1");
var scaleOut = busConfiguration.ScaleOut();
scaleOut.UseSingleBrokerQueue();
var transport = busConfiguration.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.");
}
transport.ConnectionString(connectionString);

Some things to note:

  • The use of the SamplesAzureServiceBusConnection environment variable mentioned above.
  • The use of UseSingleBrokerQueue prevents the Azure transport individualizing queue names by appending the machine name.

Viewing message in-flight

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

  • samples.azure.servicebus.endpoint1
  • samples.azure.servicebus.endpoint2
  • error
In Versions 6 and below of the transport, two additional legacy queues are created that are not utilized samples.azure.servicebus.endpoint1.retries and samples.azure.servicebus.endpoint2.retries.

Related Articles


Last modified