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

折月煮酒 提交于 2019-12-23 03:11:44

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/56064182/why-a-simple-configuration-in-masstransit-creates-2-queues-and-3-exchanges

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!