简体   繁体   中英

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

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".

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.

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