简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM