1

The document said

Published messages are routed to a receive endpoint queue by message type, using exchanges and exchange bindings. A service's receive endpoints do not affect other services or their receive endpoints, as long as they do not share the same queue.

As I know, create one ReceiveEndpoint like below will then create one exchange and one queue with the same name (e.g. some-queue), and will bind this exchange to the message type's exchange.

    services.AddMassTransit(x =>
    {
        x.AddConsumer<EventConsumer>();

        x.UsingRabbitMq((ctx, cfg) =>
        {
            cfg.ReceiveEndpoint("some-queue", e =>
            {
                e.ConfigureConsumer<EventConsumer>(ctx);
            });
        });
    });

However, I don't get the point why bother have additional "some-queue" exchange. Any example usecase will be helpful.

Charlie
  • 2,141
  • 3
  • 19
  • 35

2 Answers2

0

I cover the reasons for the topology in several videos, including this one.

Chris Patterson
  • 28,659
  • 3
  • 47
  • 59
0

I was looking for the answer to this question myself. For the benefit of the answer I paste some revised quotes of the linked video from Chris here:

MassTransit has done this since the very first versions. If you would want to to send directly to a queue you would have to either:

  • Specify a blank exchange name and set the routing key equal to the queue name.

or

  • Send to an exchange that's bound to the queue.

You can't send to a queue directly.

[...]

When we looked at the topology for the broker for MassTransit, the approach we took is to create an exchange with the same name as the queue. This gives us some actually really cool features:

Let's say I want to keep a copy of every message sent to my endpoint. I can do that by just creating another queue and binding it to that exchange. That lets me do like a wiretap which is actually a messaging pattern.

[...]

When you're troubleshooting and ask yourself: "Why didn't the service do what I suspected?": With this I can go at that queue and then I could go to my wiretap queue and look at every message that was received. This is a really cool way to kind of steal traffic and look at it and figure out what's going on.

Riscie
  • 3,775
  • 1
  • 24
  • 31