I have a task in which I try to get all the messages in a rabbit queue. I only need to GET, and not CONSUME. So here is the code, I am using
def some_function_name() :
connection = rabbitObj.get_connection()
channel = rabbitObj.get_channel(connection)
while True :
method_frame, header_frame, body = channel.basic_get(queue='error_queue', no_ack=False)
if method_frame:
#do some work
else :
break #breaking the loop
while(True):
some_function_name()
when I run this code, it works properly,first time.I get all the messages in queue and and all messages remain in 'Ready' state, but when I run the loop second time, all messages turn change to 'Unacknowledged' state.
Requirement : Every time I should only GET messages,and they should not go Unacknowledged.
First Loop:
Second Loop :
Can anyone help me with, what I am doing wrong, or what changes should I make.
Thanks in advance :)
Edit 1: As for @BarrensZeppelin 's answer, all msgs are lost, if I set no_ack=True. Check the below screenshot :
I got a workaround, and it is working. Closing the rabbit connection, after consuming did the trick.(though now it is taking time to create and close a connection everytime)