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:

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

        // Publish to a topic

            // 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();

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.

Topic Filters

If Wolverine is provisioning the subscriptions for you, you can customize the subscription filter being created.

    configureSubscriptionRule: rule =>
        rule.Filter = new SqlRuleFilter("NOT EXISTS(user.ignore) OR user.ignore NOT LIKE 'true'");

snippet source | anchor

The default filter if not customized is a simple 1=1 (always true) filter.

For more information regarding subscription filters, see the Azure Service Bus documentation.

Released under the MIT License.