Creating a test Subscription to Azure Service Bus Topic

less than 1 minute read

To solve the issue, I create another subscription, “*-test”. It’ll be only created when the service runs in Debug mode on a local development machine.

public static void ConfigureServices(HostBuilderContext context, IServiceCollection services)
{
    ....
#if DEBUG
    var client = new ManagementClient(serviceBusOptions.ConnectionString);
    foreach (var topic in new[]
    {
        EventNames.TransactionCreated,
    })
    {
        if (!client.SubscriptionExistsAsync(topic, EventNames.Subscripton).GetAwaiter().GetResult())
        {
            client.CreateSubscriptionAsync(new SubscriptionDescription(topic,
                EventNames.Subscripton));
        }
    }
#endif
    ....    

Categories:

Updated:

Comments