关于消息队列

2022-04-15 23:19:43 +08:00
 4rfv5tgb

萌新初学消息队列, 不懂就问。今天看了下 rabbitmq 的文档,有关于 prefetch_count 的设置,这个是设置消费者能拥有最多的未 ack 的消息的数量。我看官方文档说, 即使重新入队也会保证顺序。假设单个消费者,生产者发送消息 1->2->3->4->5->6->7->8->9->10, 如果 prefetch_count 设置成 30 ,那么假如 5 消息失败了没有手动 ack ,requeue 重新入队。但是 6 ,7 ,8 ,9 ,10 消费成功并且都 ack 了,这时候虽然消息看起来是按照顺序 push 了,但是消息这边消费的顺序有没有可能是 1->2->3->4->6->7->8->9->10->5 这样的顺序。我有这样的疑问:

1.在需要保证顺序的场景,现实场景中上面的情况大家都是怎么做的呢?

2.消息是否有必要持久化落表?比如说记录消费失败的 message

附上文档:

Message ordering guarantees
Section 4.7 of the AMQP 0-9-1 core specification explains the conditions under which ordering is guaranteed: messages published in one channel, passing through one exchange and one queue and one outgoing channel will be received in the same order that they were sent. RabbitMQ offers stronger guarantees since release 2.7.0.

Messages can be returned to the queue using AMQP methods that feature a requeue parameter (basic.recover, basic.reject and basic.nack), or due to a channel closing while holding unacknowledged messages. Any of these scenarios caused messages to be requeued at the back of the queue for RabbitMQ releases earlier than 2.7.0. From RabbitMQ release 2.7.0, messages are always held in the queue in publication order, even in the presence of requeueing or channel closure.

With release 2.7.0 and later it is still possible for individual consumers to observe messages out of order if the queue has multiple subscribers. This is due to the actions of other subscribers who may requeue messages. From the perspective of the queue the messages are always held in the publication order.
880 次点击
所在节点    程序员
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/847253

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX