简体   繁体   中英

Rabbitmq one queue multiple consumers

I've multiple consumers which are polling on the same queue, and checking the queue every X seconds, basically after X seconds it could be that at least two consumers can launch basic.get at the very same time.

Question are:
1.If at least two consumers at the same time can get the same message?

2.According to what I understood only basic_ack will delete a mesage from the queue, so suppose we have the following scenario:

Consumer1 takes msg with basic.get and before it reaches basic_ack line , Consumer2 is getting this message also ( basic.get ), now Consumer1 reaches the basic.ack , and only now Consumer2 reaches its own basic.ack .
What will happen When Consumer2 will reach its basic.ack ?
Will the message be processes by Consumer2 as well, because actions are not atomic?

My code logic of consumer using python pika is as follows:

while true: m_frame =None while(m_frame is None):
self.connection.sleep(10) m_frame,h_frame,body = self.channel.basic_get('test_queue') self.channel.basic_ack(m_frame.delivery_tag) [Doing some long logic - couple of minutes]

Please note that I don't use basic.consume

So I don't know if round robin fetching is included for such usage

1.If at least two consumers at the same time can get the same message?

no - a single message will only be delivered to a single consumer.

Because of that, your scenario #2 doesn't come into play at all.

You'll never have 2 consumers working on the same message, unless you nack the message back to the queue but continue processing it anyways.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM