Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent automatic creation of exchange in rabbitMQ when using consumer in masstransit?

I create a receiveEndpoint with masstransit and consume it like this :

var busControl = Bus.Factory.CreateUsingRabbitMq(cfg =>
{
    cfg.ReceiveEndpoint("my-endpoint", x =>
    {
        x.Consumer<MyEndpointConsumer>();
    });
}

Here my class MyEndpointConsumer :

class MyEndpointConsumer : IConsumer<IMyEndpoint>
{
    public Task Consume(ConsumeContext<IMyEndpoint> context)
    {
        Console.WriteLine("MyEndpointConsumer");
    }
}

MassTransit create :

  • a queue : "my-endpoint"
  • a first exchange : "my-endpoint"
  • a second exchange : "IMyEndpoint"

I want to disabled the creation of this second exchange. MassTransit documentation explain that consumer topology is based on "publish topology" (MassTransit documentation) :

The consume topology uses the publish topology to ensure consistent naming of exchanges/topics for message types.

So I try to change publish topology on my interface "IMyEndpoint" :

cfg.Publish<IMyEndpoint>(x =>
{
    x.Exclude = true;
});

but nothing change, I try :

[ExcludeFromTopology]
publiv interface IMyEndpoint

nothing change too.

Have got any ideas to prend this exchange creation ?

Thanks for your help.

like image 309
loic49 Avatar asked Nov 23 '25 11:11

loic49


1 Answers

The consumed message type cannot be excluded. Inherited types can be excluded, but not the actual consumed message type as this would prevent published messages from reaching the consumer queue.

If you want to disable the exchange and at the same time prevent published messages from reaching the queue, set ConfigureConsumeTopology = false on the receive endpoint configurator.

like image 93
Chris Patterson Avatar answered Nov 26 '25 01:11

Chris Patterson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!