RabbitMQ 交换:默认与直接 [英] RabbitMQ exchanges: default vs. direct

查看:43
本文介绍了RabbitMQ 交换:默认与直接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两种类型的消息要通过 RabbitMQ 发送.所以我有 2 个选项可以做到这一点:

I have exactly 2 types of messages that I want to be sent via RabbitMQ. So I have 2 options how I can do this:

  • 使用与队列名称对应的routing_key 向默认的空名交换发送消息
  • 在队列绑定中使用direct交换的routing_key参数对应消费者的routing_key参数
  • sent a message to default empty-named exchange with routing_key corresponding to the queue name
  • use direct exchange's routing_key parameter corresponding to consumer's routing_key parameter in queue binding

那么哪个选项更可取,为什么?

So which option is preferable and why?

推荐答案

默认交换直接交换.RabbitMQ 默认创建默认交换,但它使用空字符串作为名称.如果您查看 RabbitMQ AMQP 概念页面,在默认交换下:

A default exchange is a direct exchange. RabbitMQ creates the default exchange by default, but it uses an empty string for the name. If you look at the RabbitMQ AMQP concepts page, under Default Exchange:

默认交换是没有名字的直接交换(空字符串)由经纪人预先声明.

The default exchange is a direct exchange with no name (empty string) pre-declared by the broker.

您也可以通过运行 rabbitmqctl list_exchanges 来查看:

You can see this by running rabbitmqctl list_exchanges as well:

                direct
Foo             direct    < Same thing as the above
amq.direct      direct
amq.fanout      fanout
...and so on

据我所知,使用一个比另一个没有任何好处.如果您只需要根据路由键进行路由,我会坚持使用默认交换.

As far as I'm aware, there isn't any benefits of using one over the other. I would stick with the default exchange if you only need to route based on routing keys.

这篇关于RabbitMQ 交换:默认与直接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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