Skip to content

Object Management

When using the Azure Service Bus transport, Wolverine is able to use the stateful resource model where all missing queues, topics, and subscriptions would be built at application start up time with this option applied:

cs
using var host = await Host.CreateDefaultBuilder()
    .UseWolverine(opts =>
    {
        opts.UseAzureServiceBus("some connection string");

        // Make sure that all known resources like
        // the Azure Service Bus queues, topics, and subscriptions
        // configured for this application exist at application start up
        opts.Services.AddResourceSetupOnStartup();
    }).StartAsync();

snippet source | anchor

You can also direct Wolverine to build out Azure Service Bus object on demand as needed with:

cs
using var host = await Host.CreateDefaultBuilder()
    .UseWolverine(opts =>
    {
        opts.UseAzureServiceBus("some connection string")
            
            // Wolverine will build missing queues, topics, and subscriptions
            // as necessary at runtime
            .AutoProvision();
    }).StartAsync();

snippet source | anchor

You can also opt to auto-purge all queues (there's also an option to do this queue by queue) on application start up time with:

cs
using var host = await Host.CreateDefaultBuilder()
    .UseWolverine(opts =>
    {
        opts.UseAzureServiceBus("some connection string")
            .AutoPurgeOnStartup();
    }).StartAsync();

snippet source | anchor

And lastly, because Azure Service Bus is a centralized broker model and you may have to share a single environment between multiple developers or development environments, you can use prefixing with Azure Service Bus so that every queue, topic, and subscription is quietly prefixed for uniqueness:

Configuring Queues

If Wolverine is provisioning the queues for you, you can use one of these options shown below to directly control exactly how the Azure Service Bus queue will be configured:

cs
using var host = await Host.CreateDefaultBuilder()
    .UseWolverine((context, opts) =>
    {
        // One way or another, you're probably pulling the Azure Service Bus
        // connection string out of configuration
        var azureServiceBusConnectionString = context
            .Configuration
            .GetConnectionString("azure-service-bus");

        // Connect to the broker in the simplest possible way
        opts.UseAzureServiceBus(azureServiceBusConnectionString).AutoProvision()

            // Alter how a queue should be provisioned by Wolverine
            .ConfigureQueue("outgoing", options => { options.AutoDeleteOnIdle = 5.Minutes(); });

        // Or do the same thing when creating a listener
        opts.ListenToAzureServiceBusQueue("incoming")
            .ConfigureQueue(options => { options.MaxDeliveryCount = 5; });

        // Or as part of a subscription
        opts.PublishAllMessages()
            .ToAzureServiceBusQueue("outgoing")
            .ConfigureQueue(options => { options.LockDuration = 3.Seconds(); })
            
            // You may need to change the maximum number of messages
            // in message batches depending on the size of your messages
            // if you hit maximum data constraints
            .MessageBatchSize(50);
    }).StartAsync();

snippet source | anchor

Released under the MIT License.