生产者通过消息队列一致地向消费者进行散列?
我有一个生产者,我想通过一致的散列在消费者之间一致地分配工作。例如,对于消费者节点 X 和 Y,任务 A、B、C 应始终分配给消费者 X,而 D、E、F 应分配给消费者 Y。但如果 Z 加入消费者池,情况可能会发生一些变化。
我不想编写自己的逻辑来连接到消费者节点,尤其是不想管理节点加入和离开池,所以我沿着使用 RabbitMQ 的道路,以及每个消费者节点的独占队列。
我遇到的一个问题是列出这些队列,因为生产者需要在分发工作之前知道所有可用的队列。 AMQP 甚至不支持列出队列,这让我不确定我的整个方法。 RabbitMQ 和 Alice(目前已损坏 )添加该功能: 是否有 API用于在 RabbitMQ 上列出队列和交换器?
这是 Rabbit 的明智使用吗?我应该使用消息队列吗?是否有更好的设计,以便队列可以一致在消费者之间分配我的工作,而不是我需要这样做?
I have a producer that I want to distribute work consistently across consumers by consistent hashing. For example, with consumer nodes X and Y, tasks A, B, C should always go to consumer X, and D, E, F to consumer Y. But that may shift a little if Z joins the pool of consumers.
I didn't want to deal with writing my own logic to connect to the consumer nodes, and especially not with managing nodes joining and leaving the pool, so I've gone down the path of using RabbitMQ, and an exclusive queue per consumer node.
One problem I'm running into is listing these queues, since the producer needs to know all the available queues before work is distributed. AMQP doesn't even support listing queues, which makes me uncertain of my whole approach. RabbitMQ and Alice (brokenly at the moment) add that functionality though: Is there an API for listing queues and exchanges on RabbitMQ?
Is this a wise use of Rabbit? Should I be using a message queue at all? Is there a better design so the queue can consistently divide my work among consumers, instead of me needing to do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您所描述的内容在 RabbitMQ 中是可行的。
您的设置类似于:
因此,如果您有 6 种任务类型:A、B、C、D、E、F,并且只有两个使用者 C1 和 C2,则您的绑定将如下所示: C1 使用路由键 A、B 和 C 绑定 3 次到一致性分隔符; C2 使用路由键 D、E 和 F 与 c_d 绑定了 3 次。
当 C3 加入池时,生产者会看到这一点并相应地重新绑定队列。
当生产者发布时,它会使用routing_keys A、B、C、D、E和/或F发送消息,并且消息将被路由到正确的队列。
这会存在两个潜在的问题:
为了回答你的最后一个问题,你可能想使用队列,而 RabbitMQ 是一个不错的选择,但你的要求(更准确地说是“一致地分配工作”位)不太适合 AMQP。
What you describe is do-able in RabbitMQ.
Your setup would be something like:
So, if you have 6 task types: A, B, C, D, E, F, and only two consumers C1 and C2, your bindings would look like: C1 bound 3 times to consistent_divider with routing keys A, B and C; C2 bound 3 times to c_d with routing keys D, E and F.
When C3 joins the pool, the producer sees this and rebinds the queues accordingly.
When the producer publishes, it sends out the messages with routing_keys A, B, C, D, E and/or F, and the messages will get routed to the correct queues.
There would be two potential problems with this:
To answer your last question, you probably want to use queuing and RabbitMQ is a great choice, but your requirements (more precisely the `divide the work consistently' bit) don't quite fit AMQP perfectly.
您可以使用rabbitmq的官方 consistent-hashing 插件作为回答这里
You could use the official consistent-hashing plugin for rabbitmq as answered here