在确认第一个消息后发送第二个消息.RabbitMQ 是否保证顺序?

编程入门 行业动态 更新时间:2024-10-24 10:28:03
本文介绍了在确认第一个消息后发送第二个消息.RabbitMQ 是否保证顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

假设有几个生产者发布到同一个交易所 E(扇出).每个生产者都有自己的频道.队列 Q 绑定到交换机 E.生产者 P1 向 E 发布消息 M1,并从 E 收到确认 A1.只有在确认 A1 之后,第二个生产者 P2 才发布第二条消息 M2.Q:M1 第一,M2 次之,RabbitMQ 是否保证消息的顺序?那就是订阅 Q 的消费者总是收到 M1,然后是 M2?

Assume several producers publish to the same exchange E (fanout). Each producer has its own channel. Queue Q is bound to exchange E. producer P1 publishes message M1 to E and receives acknowledge A1 from E. Only after acknowledge A1 second producer P2 publishes second message M2. Does RabbitMQ guarantie order of messages in Q: M1 is first, M2 is second? That is will subscribed to Q consumer always receive M1 and after that M2?

推荐答案

RabbitMQ 保证队列中消息的顺序:先进先出.进入队列的第一条消息将是从队列中出来的第一条消息,它们将保持有序(假设您只是在消费和确认它们......如果您开始确认/拒绝消息,重新发布它们等,事情发生了变化)

RabbitMQ guarantees order of messages in a queue: First In, First Out. The first message to go into the queue will be the first message to come out of the queue, and they will remain in order (assuming you are just consuming and acking them... if you start nacking / rejecting message, re-publishing them, etc, things change)

这是按消息顺序进行的唯一保证:FIFO 队列.

That is the only guarantee that it will make on the order of messages: FIFO Queues.

如果您需要保证消息传递到队列的顺序,则必须自己构建该流程.

If you need to guarantee the order that messages are delivered to a queue, you have to build that process yourself.

FWIW,建立这种保证非常困难.确保消息顺序的唯一真正有保证的方法是在处理完第一个消息之前不要发送下一个消息.

FWIW, it's very difficult to build this guarantee. The only truly guaranteed way to ensure the order of messages is not to send the next one until after the first one has been processed.

即使您在发送下一个之前等待发布者确认,下一个也有可能在第一个之前在队列中结束(尽管可能性很小).

Even if you wait for the publisher acknowledgement before sending the next one, it is possible for the next one to end up in the queue before the first one (though it is highly unlikely).

您可能需要查看消息序列和Resequencer 如果您需要保证客户端按特定顺序接收消息.

You may want to look into Message Sequence and Resequencer if you need to guarantee the client gets messages in a certain order.

更多推荐

在确认第一个消息后发送第二个消息.RabbitMQ 是否保证顺序?

本文发布于:2023-11-05 12:33:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1560857.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:消息   第一个   第二个   顺序   RabbitMQ

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!