RabbitMQ 扇出主题交换 [英] RabbitMQ fan out on a topic exchange

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

问题描述

RabbitMQ 还很新,我们仍处于调查阶段,看看它是否适合我们的用例--

Pretty new to RabbitMQ and we're still in the investigation stage to see if it's a good fit for our use cases--

我们很容易得出结论,我们想要的拓扑会让我们部署一些基于主题的交换,然后从那里过滤到特定的队列.例如,假设我们有一个用户和一个上传交换,其中用户队列可能会收到主题为新注册"或好友请求"的消息,而上传交换可能会收到诸如视频上传"或图片上传".

We've readily come to the conclusion that our desired topology would have us deploying a few topic based exchanges, and then filtering from there to specific queues. For example, let's say we have a user and an upload exchange, where the user queue might receive messages where the topic is "new-registration" or "friend-request" and the upload exchange might receive messages like "video-upload" or "picture-upload".

创建队列,将它们路由到适当的队列,然后构建侦听器来处理各种队列的消息非常简单.

Creating the queues, getting them routed to the appropriate queue, and then building listeners to handle the messages for the various queues has been quite straight forward.

但是我不清楚的是是否可以在主题交换中进行扇出?

What's unclear to me however is if it's possible to do a fanout on a topic exchange?

即我已经命名了绑定到我的主题交换的队列,但我希望能够在这些队列中抛出大量我的侦听器实例以防止单点故障.但据我所知,RabbitMQ 以一种直接的循环方式对待这些听众——例如每条第 N 个消息总是发送到同一个第 N 个侦听器,而不是将消息分派给第一个可用的消费者.这对我们来说通常是可以接受的,但考虑到我们预期的负载,我们希望避免在我们的消费者农场中出现热点的可能性.

I.e. I have named queues that are bound to my topic exchange, but I'd like to be able to just throw tons of instances of my listeners at those queues to prevent single points of failure. But to the best of my knowledge, RabbitMQ treats these listeners in a straight forward round robin fashion--e.g. every Nth message always go to the same Nth listener rather than dispatching messages to the first available consumer. This is generally acceptable to us but given the load we anticipate, we'd like to avoid the possibility of hot spots developing amongst our consumer farm.

那么,在队列或交换配置或消费者代码中,是否有某种方法可以让我们的侦听器指向主题队列,但以扇出方式处理侦听器?

So, is there some way, either in the queue or exchange configuration or in the consumer code, where we can point our listeners to a topic queue but have the listeners treated in a fanout fashion?

推荐答案

是的,通过让侦听器使用不同的队列名称进行绑定,它们将以扇出方式进行处理.

Yes, by having the listeners bind using different queue names, they will be treated in a fanout fashion.

Fanout 是 1:N,即每个任务都可以传递给多个侦听器,例如 pub-sub.请注意,这不仅限于扇出交换,还适用于将多个队列绑定到具有相同绑定键的直接或主题交换.(安装管理插件并查看那里的交换可能有助于可视化有效的绑定.)

Fanout is 1:N though, i.e. each task can be delivered to multiple listeners like pub-sub. Note that this isn't restricted to a fanout exchange, but also applies if you bind multiple queues to a direct or topic exchange with the same binding key. (Installing the management plugin and looking at the exchanges there may be useful to visualize the bindings in effect.)

您当前的设置是任务队列.每个任务/消息都准确地传递给一个工作人员/侦听器.在相同的队列名称上抛出更多的侦听器,他们将按照您所说的方式循环处理任务.使用扇出"(一个主题的单独队列),您将多次处理一个任务.

Your current setup is a task queue. Each task/message is delivered to exactly one worker/listener. Throw more listeners at the same queue name, and they will process the tasks round-robin as you say. With "fanout" (separate queues for a topic) you will process a task multiple times.

根据您的平台,可能存在满足您要求的现有工作队列解决方案,例如用于 Ruby 的 Resque 或 DelayedJob、用于 Python 的 Celery 或用于 JVM 的 Octobot 或 Akka.

Depending on your platform there may be existing work queue solutions that meet your requirements, such as Resque or DelayedJob for Ruby, Celery for Python or perhaps Octobot or Akka for the JVM.

这篇关于RabbitMQ 扇出主题交换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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