Why a simple configuration in MassTransit creates 2 queues and 3 exchanges?
Asked Answered
B

1

6

I created a MassTransit quickstart program to interact with my localhost RabbitMQ:

namespace ConsoleApp1
{
    public static class Program
    {
        public class YourMessage
        {
            public string Text { get; set; }
        }

        public static async Task Main(params string[] args)
        {
            var bus = Bus.Factory.CreateUsingRabbitMq(sbc =>
            {
                var host = sbc.Host(new Uri("rabbitmq://localhost"), h =>
                {
                    h.Username("guest");
                    h.Password("guest");
                });

                sbc.ReceiveEndpoint(host, "test_queue", ep =>
                {
                    ep.Handler<YourMessage>(async context => await Console.Out.WriteLineAsync($"Received: {context.Message.Text}"));
                });
            });

            await bus.StartAsync(); 
            await bus.Publish(new YourMessage{Text = "Hi"});
            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
            await bus.StopAsync();
        }
    }
}

Everything looked fine untill I actually checked the underlying RabbitMQ management and found out that just for this very simple program, MassTransit created 3 exchanges and 2 queues.

Exchanges, all fanouts:

  • ConsoleApp1:Program-YourMessage: Durable
  • VP0003748_dotnet_bus_6n9oyyfzxhyx9ybobdmpj8qeyt: Auto-delete and Durable?
  • test_queue: Durable

Queues:

  • VP0003748_dotnet_bus_6n9oyyfzxhyx9ybobdmpj8qeyt: x-expire 60000
  • test_queue: Durable

I would like to know why all of that is necessary or is the default configuration? In particular, I am not really sure to get the point of creating so "many".

Bromleigh answered 9/5, 2019 at 16:54 Comment(2)
Which version of MassTransit do you use? This issue is reproducible with version 5.5.6, but version 6.0.0 does not create unused auto-delete exchange and queue. As for now, cannot locate commit when it has been fixed (github.com/MassTransit/MassTransit/releases/tag/v6.0.0)Courtier
@PylypLebediev I believed that back then it was version 5.5.5.Bromleigh
C
6

It is all described in the documentation.

ConsoleApp1:Program-YourMessage is the message contract exchange, here messages are being published.

test_queue is the endpoint exchange. It binds to the message exchange. This way, when you have multiple consumers for the same message type (pub-sub), they all get their copy of the message.

test_queue is the queue, which binds to the endpoint exchange. Publish-subscribe in RMQ requires exchanges and queues can find to exchanges, so messages get properly delivered.

Both non-durable queue and exchange with weird names are the endpoint temp queue and exchange, which are used for request-response.

Chlori answered 9/5, 2019 at 18:2 Comment(5)
I can't find that information in the documentation, can I prevent the creation of the non durable queue and exchange? I mean if we don't use the request-response but just regular publishing? Also it is an issue to have the same exchange name for different .NET types?Bromleigh
I don't think so, but what is exactly the issue with having them?Chlori
just would like a way either to change their name with something more explicit or to avoid their creation. I mean if we don't use that feature of RabbitMQ, what's the point of having them?Bromleigh
Name of message queues can be changed by using sbc.OverrideDefaultBusEndpointQueueName("endpoint"); method of IRabbitMqBusFactoryConfiguratorCourtier
The link is broken in the answer, but I cannot edit it because there are too many pending edits. Current link (MassTransit v8): masstransit.io/documentation/configuration/transports/…Norvell

© 2022 - 2024 — McMap. All rights reserved.