Azure Functions with Azure Service Bus Upgrade Version 1 to 2

Registering NServiceBus

All public constructors of ServiceBusTriggeredEndpointConfiguration have been made internal.

Instead of

functionsHostBuilder.UseNServiceBus(() => new ServiceBusTriggeredEndpointConfiguration(endpointName));

use:

functionsHostBuilder.UseNServiceBus(endpointName);

The endpoint name can be inferred from NServiceBusTriggerFunctionAttribute if present.

[assembly: NServiceBusTriggerFunction("MyEndpoint")]

// ...

functionsHostBuilder.UseNServiceBus(); // Will use the name MyEndpoint
The constructed instance of NServiceBusTriggeredEndpointConfiguration already contains a reference to an IConfiguration instance from the host environment. It is not required to pass one in.

Connection strings

Specifying a connection string by name has been deprecated.

Instead of

functionsHostBuilder.UseNServiceBus(
    () => new ServiceBusTriggeredEndpointConfiguration(endpointName, connectionStringName)
);

use:

functionsHostBuilder.UseNServiceBus(endpointName, nsb =>
{
    var connectionString = Environment.GetEnvironmentVariable(connectionStringName);
    nsb.ServiceBusConnectionString = connectionString;
});

Routing

Instead of

functionsHostBuilder.UseNServiceBus(() =>
{
    var serviceBusTriggeredEndpointConfiguration = new ServiceBusTriggeredEndpointConfiguration(endpointName);
    var routing = serviceBusTriggeredEndpointConfiguration.Transport.Routing();
    routing.RouteToEndpoint(typeof(SomeMessage), "AnotherEndpoint");

    return serviceBusTriggeredEndpointConfiguration;
});

use:

functionsHostBuilder.UseNServiceBus(endpointName, nsb =>
{
    nsb.Routing.RouteToEndpoint(typeof(SomeMessage), "AnotherEndpoint");
});

Related Articles


Last modified