RabbitMQ Message Sequence Guarantee

I have a project that involves rabbitmq. The problem that I have is illustrated as follows:

Problem

So now, let me describe the scenario. I have n number of queues which subscribed to topic1 . Now my question is if I publish 3 messages in sequence, which are shown as 1, 2 and 3 into broker called Exchange , will rabbitmq Guarantee the sequence of those messages in all queues?

The only thing that I found was in rabbitmq documentation Message ordering guarantees which was taking about

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.

So can anyone help me out and point me to the right doc or example that shows whether it is guaranteed or not?

Thanks


What you have quoted answers your question perfectly. The only question is what your consumer set up looks like. If you have each queue connected to its own channel and that consumer is running in its own thread, that thread will see each message in order as they were published.


As the other poster mentioned, your scenario should work fine assuming a simple/basic consumer setup. But here's some additional info that might explain why.

I wasn't sure quite what nuances might have been wrapped up in that section of the documentation either, until I looked up exactly what a Channel was. A connection to RabbitMQ can have multiple "mini-connections" within it called channels . Each of these channels are independent and thus you could send multiple messages to the broker via multiple channels.

So as long as the messages in your scenario are sent on a single channel (you'd have to explicitly try to use multiple channels), they'll arrive in the queue in the same order you sent them. As long as the messages are consumed via a single channel, they'd arrive on the consumer in the same order they arrived in the queue (also being the same order they were sent).

From: https://www.rabbitmq.com/tutorials/amqp-concepts.html

Some applications need multiple connections to an AMQP broker. However, it is undesirable to keep many TCP connections open at the same time because doing so consumes system resources and makes it more difficult to configure firewalls. AMQP 0-9-1 connections are multiplexed with channels that can be thought of as "lightweight connections that share a single TCP connection".

链接地址: http://www.djcxy.com/p/5838.html

上一篇: AMQP有什么意义?

下一篇: RabbitMQ消息序列保证