Reputation: 6242
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
Upvotes: 1
Views: 1777
Reputation: 72888
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.
Upvotes: 2