AMQP/RabbitMQ-按顺序处理消息 [英] AMQP/RabbitMQ - Process messages sequentially

查看:135
本文介绍了AMQP/RabbitMQ-按顺序处理消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个直接交流中心.还有一个队列,绑定到此交换.

该队列有两个使用者.使用者完成相应的处理后,便会手动确认消息.

消息在逻辑上是按顺序排列/排序的,应按该顺序进行处理.是否可以强制要求在消费者A和消费者B之间依次接收和处理所有消息?换句话说,请防止A和B同时处理邮件.

注意:消费者共享相同的连接和/或渠道.这意味着我不能使用<channel>.basicQoS(1);.

这个问题的理论依据:两个消费者都是相同的.如果其中一个发生故障,则另一个队列开始处理消息,并且一切正常,而无需任何干预.

解决方案

通常,MQ系统的重点是分配工作负载.当然,在某些情况下,消息N的处理取决于消息N-1或N-1消息本身的处理结果.

如果A和B无法同时处理消息,那么为什么不只有A或只有B?正如我所看到的,拥有2个消费者不会使您节省任何钱,因为一个消费者只有在另一个消费者无法工作时才可以工作...

在您的情况下,最好只有一个使用者,但实际上要在处理部分进行并行化(实际上不是一个字).

只需补充说,RMQ不管任何条件如何都将消息均匀地分发给所有使用者(以循环方式).当然,这是预取设置为1时的默认值. 此处的更多信息,寻找公平派送". >

I have one direct exchange. There is also one queue, bound to this exchange.

I have two consumers for that queue. The consumers are manually ack'ing the messages once they've done the corresponding processing.

The messages are logically ordered/sorted, and should be processed in that order. Is it possible to enforce that all messages are received and processed sequentially accross consumer A and consumer B? In other words, prevent A and B from processing messages at the same time.

Note: the consumers are not sharing the same connection and/or channel. This means I cannot use <channel>.basicQoS(1);.

Rationale of this question: both consumers are identicall. If one goes down, the other queue starts processing messages and everything keeps working without any required intervention.

解决方案

Usually the point of a MQ system is to distribute workload. Of course, there are some situations where processing of message N depends on result of processing the message N-1, or even the N-1 message itself.

If A and B can't process messages at the same time, then why not just have A or just B? As I see it, you are not saving anything with having 2 consumers in a way that one can work only when the other one is not...

In your case, it would be best to have one consumer but to actually do the parallelisation (not a word really) on the processing part.

Just to add that RMQ is distributing messages evenly to all consumers (in round-robin fashion) regardless on any criteria. Of course this is when prefetch is set to 1, which by default it is. More info on that here, look for "fair dispatch".

这篇关于AMQP/RabbitMQ-按顺序处理消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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