Search code examples
c#.net-coremasstransit

Setting specific Routing Key to all Receive Endpoints in MassTransit


I have a microservice which has over 15 consumers. I would like to know if it is possible to set a RoutingKey for all of the receive endpoints without manually configuring each of them please.

I tried to use AddConfigureEndpointsCallback but I cannot see how to implement this.

Your help is appreciated.

Thanks


Solution

  • I figured it out. Answering it here as someone else might find it useful:

    config.AddConfigureEndpointsCallback((name, receiveEndpointConfig) =>
    {
         if (receiveEndpointConfig is not IRabbitMqReceiveEndpointConfigurator rabbitMqConfigurator)
         {
             return;
         }
    
         rabbitMqConfigurator.Bind(name, callback =>
         {
             callback.RoutingKey = "your-routing-key";
         });
     });