为什么在MassTransit中进行简单配置会创建2个队列和3个交换? [英] Why a simple configuration in MassTransit creates 2 queues and 3 exchanges?

查看:183
本文介绍了为什么在MassTransit中进行简单配置会创建2个队列和3个交换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个MassTransit快速入门程序来与我的本地RabbitMQ交互:

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();
        }
    }
}

一切都很好,直到我实际检查了底层RabbitMQ管理并发现,对于这个非常简单的程序,MassTransit创建了3个交换和2个队列.

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.

交流,所有扇出:

  • ConsoleApp1:Program-YourMessage:耐用
  • VP0003748_dotnet_bus_6n9oyyfzxhyx9ybobdmpj8qeyt:自动删除并且持久吗?
  • test_queue:耐用
  • ConsoleApp1:Program-YourMessage: Durable
  • VP0003748_dotnet_bus_6n9oyyfzxhyx9ybobdmpj8qeyt: Auto-delete and Durable?
  • test_queue: Durable

队列:

  • VP0003748_dotnet_bus_6n9oyyfzxhyx9ybobdmpj8qeyt:x到期60000
  • test_queue:耐用
  • 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".

推荐答案

ConsoleApp1:Program-YourMessage是消息合同交换,此处正在发布消息.

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

test_queue是端点交换.它绑定到消息交换.这样,当您有多个使用者使用相同的消息类型(pub-sub)时,他们都会获得消息的副本.

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是队列,绑定到端点交换. RMQ中的发布-订阅要求进行交换,并且队列可以找到要交换的消息,因此消息可以正确传递.

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.

这篇关于为什么在MassTransit中进行简单配置会创建2个队列和3个交换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆