Skip to content

Topics and Subscriptions

Wolverine.AzureServiceBus supports Azure Service Bus topics and subscriptions.

To register endpoints to send messages to topics or to receive messages from subscriptions, use this syntax:

cs
using var host = await Host.CreateDefaultBuilder()
    .UseWolverine(opts =>
    {
        opts.UseAzureServiceBus("some connection string")
            
            // If this is part of your configuration, Wolverine will try to create
            // any missing topics or subscriptions in the configuration at application
            // start up time
            .AutoProvision();
        
        // Publish to a topic
        opts.PublishMessage<Message1>().ToAzureServiceBusTopic("topic1")
            
            // Option to configure how the topic would be configured if
            // built by Wolverine
            .ConfigureTopic(topic =>
            {
                topic.MaxSizeInMegabytes = 100;
            });

        opts.ListenToAzureServiceBusSubscription("subscription1", subscription =>
            {
                // Optionally alter how the subscription is created or configured in Azure Service Bus
                subscription.DefaultMessageTimeToLive = 5.Minutes();
            })
            .FromTopic("topic1", topic =>
            {
                // Optionally alter how the topic is created in Azure Service Bus
                topic.DefaultMessageTimeToLive = 5.Minutes();
            });
    }).StartAsync();

snippet source | anchor

To fully utilize subscription listening, be careful with using Requeue error handling actions. In order to truly make that work, Wolverine tries to build out a queue called wolverine.response.[Your Wolverine service name] specifically for requeues from subscription listening. If your Wolverine application doesn't have permissions to create queues at runtime, you may want to build that queue manually or forgo using "Requeue" as an error handling technique.

Released under the MIT License.