使用MassTransit使用交换和路由密钥发布消息 [英] Publish message using exchange and routing key using MassTransit

查看:113
本文介绍了使用MassTransit使用交换和路由密钥发布消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看了MassTransit两周了,我对这种可能性感到好奇.但是,我似乎无法完全正确地理解这些概念.

I've been looking at MassTransit for a couple of weeks now and I'm curious about the possibilities. However, I don't seem to be able to get the concepts quite right.

预期行为 我想发布消息以通过路由键直接"交换,该路由键绑定到两个用于执行其他活动的不同队列.

Expected behaviour I wanted to publish message to "direct" exchange with routing key which is bind to two different queue for performing other activities.

当我尝试使用MassTransit进行相同的逻辑以获得更好的可伸缩性时.我发现MassTransit根据具有扇出类型的队列名称创建自己的交换.

When I attempted the same logic using MassTransit for better scalability. I've found MassTransit creates own exchange based on queue name with fanout type.

用于通过交换和路由键发布消息的经典代码

Classic code to publish message by exchange and routing key

using (var connection = factory.CreateConnection())
        {
            using (var channel = connection.CreateModel())
            {
                channel.ExchangeDeclare(exchange, "direct");

                var body = Encoding.UTF8.GetBytes(message);

                channel.BasicPublish(exchange, routingKey, null, body);
                Console.WriteLine(" [x] Sent {0}", message);
            }
        }

是否可以使用MassTransit中的routingkey配置直接或主题交换?

推荐答案

MassTransit不支持此方案. MassTransit将始终创建扇出队列.如果您自己管理拓扑,则可以使用IEndpoint.Send直接将消息发送到您创建的交换机.在这种情况下,您将放弃MT所提供的一切.

This is not a supported scenario with MassTransit. MassTransit will always create a fanout queue. If you managed your topology yourself, you can use IEndpoint.Send to directly send the message to the exchange you created. In this case you give up much what MT provides though.

在这种情况下,我也不确定更好的可伸缩性"是什么意思.在大多数情况下,扇出交换比直接交换的性能更好,因为不需要处理路由逻辑.

I'm also not sure what "better scalability" means in this case. Fanout exchanges perform better than direct exchanges (in most cases) since there's no routing logic that needs to be processed.

也许,如果您在 MassTransit邮件列表中澄清了对性能的关注,我们可以在那里为您提供更多帮助.

Maybe if you clarified your performance concerns on the MassTransit mailing list we could help you a bit more there.

这篇关于使用MassTransit使用交换和路由密钥发布消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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