RabbitMQ:下一条消息只有在上一条消息被确认后才能出队 [英] RabbitMQ: next message can be dequeued only after previous was acked

查看:33
本文介绍了RabbitMQ:下一条消息只有在上一条消息被确认后才能出队的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 RabbitMQ 中的队列上有这个约束:

I would like to have this constraint on a queue in RabbitMQ:

队列中的下一条消息在前一条消息(正在处理的消息)被确认之前不能出队.

Next message in the queue can't be dequeued before previous message (the one being processed) is acked.

通过这个,我将实现事件的有序处理和跨多个队列的并行处理.我如何/可以为此配置 RabbitMQ?

Through this I will achieve ordered processing of events and parallel processing across multiple queues. How do I/can I configure RabbitMQ for this?

编辑(澄清):将有许多消费者都试图从所有队列中获取工作,并且由于他们无法从正在处理的事件未确认的队列中获取工作 - 保持有序处理.

Edit (clarification): There will be many consumers all trying to get work from all the queues and since they can't get work from a queue that has an event being processed that isn't acked - ordered processing is maintained.

推荐答案

在前一条消息(正在处理的消息)被确认之前,队列中的下一条消息不能出队.

Next message in the queue can't be dequeued before previous message (the one being processed) is acked.

您可以通过单个消费者的消费者预取限制来做到这一点.

you can do this through the consumer prefetch limit for a single consumer.

通过这个我将实现事件的有序处理和跨多个队列的并行处理.

Through this I will achieve ordered processing of events and parallel processing across multiple queues.

很遗憾,这不会产生您想要的效果.

unfortunately, this won't have the effect that you want.

您可以为个人消费者设置.该消费者将等待一条消息得到确认,然后再获取下一条消息.

you can set for an individual consumer. that consumer will wait for a message to be acknowledged before getting the next one.

但是,这适用于个人消费者,而不是队列.

However, this applies to the individual consumer, not the queue.

如果您有 2 个消费者,他们每个人都会并行处理一条消息.如果您有 10 个消费者,则将并行处理 10 条消息.

if you have 2 consumers, each of them will process a message in parallel. if you have 10 consumers, 10 messages will be processed in parallel.

按顺序处理每条消息的唯一方法是拥有一个预取为 1 的消费者.

the only way to process every message in order, is to have a single consumer with a prefetch of 1.

这篇关于RabbitMQ:下一条消息只有在上一条消息被确认后才能出队的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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