1

We configure MassTransit to use Azure Service Bus in this way:

                mtConfig.UsingAzureServiceBus((context, busConfig) =>
                {
                    busConfig.Host(new HostSettings
                    {
                        ServiceUri = new Uri(xxx),
                        TokenProvider = TokenProvider.CreateManagedIdentityTokenProvider()
                    });

                    busConfig.ConfigureJsonSerializer(ConfigureJsonSerialization);
                    busConfig.ConfigureJsonDeserializer(ConfigureJsonSerialization);
                    busConfig.ConfigureEndpoints(context);
                });

How can we set e.g. subscription properties like EnableDeadLetteringOnMessageExpiration for all the subscriptions created automatically by MassTransit?

Thanks, Peter

Update

I've tried this (EnableDeadLetteringOnMessageExpiration), but the dead letter option isn't enabled on the subscriptions in the Azure Service Bus (we've deleted all the topics and subscriptions first, so that they were newly created):

            mtConfig.UsingAzureServiceBus((context, busConfig) =>
            {
                busConfig.Host(new HostSettings
                {
                    ServiceUri = new Uri(xxx),
                    TokenProvider = TokenProvider.CreateManagedIdentityTokenProvider()
                });

               busConfig.EnableDeadLetteringOnMessageExpiration = true;

               busConfig.ConfigureJsonSerializer(ConfigureJsonSerialization);
               busConfig.ConfigureJsonDeserializer(ConfigureJsonSerialization);
               busConfig.ConfigureEndpoints(context);
            });
Peter Wyss
  • 395
  • 2
  • 16

1 Answers1

1

You can create a class that implements IConfigureReceiveEndpoint (see the docs) and in that function, pattern match the configurator to see if it is Azure Service Bus and set the properties. When registered in the container, MassTransit will run the class against each endpoint.

class ConfigureMyEndpoint :
    IConfigureReceiveEndpoint
{
    public void Configure(string name, IReceiveEndpointConfigurator configurator)
    {
        if(configurator is IServiceBusReceiveEndpointConfigurator sb)
        {
            sb.EnableDeadLetteringOnMessageExpiration = true;
        }
    }
}
Chris Patterson
  • 28,659
  • 3
  • 47
  • 59