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

查看:23
本文介绍了为什么 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-expire 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 是端点交换.它绑定到消息交换.这样,当您有多个消费者使用相同的消息类型(发布-订阅)时,他们都会获得消息的副本.

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天全站免登陆