Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get message from RabbitMQ without consuming

I would like to get a copy of the messages present in a Rabbitmq queue without consuming them. Is it possible ? Thanks in advance,

like image 282
k.Sugetha Avatar asked Mar 19 '26 19:03

k.Sugetha


2 Answers

I would like to get a copy of the messages present in a Rabbitmq queue without consuming them. Is it possible?

No. The closest option you have is to consume or get a message and then reject it via a negative acknowledgement.

like image 93
Luke Bakken Avatar answered Mar 22 '26 10:03

Luke Bakken


may be you can register a consumer (as shown here in the official doc) without giving ack to the broker: no_ack=True

channel.basic_consume(callback, queue='hello', no_ack=True)

This way your consumer receives the message content but the message itself is not marked as delivered by the broker (and returns to Ready state when you consumer exits).

May be this is not the cleanest way to do what you need, but it works and it's simple.

Another (but similary) approach you can adopt is based on the so-called pull API (in opposite to push API you use when you register a subscriber); I used this approach in a .Net application: you can find the .Net documentation here and I think Python APIs are similar in that, too.

The key idea is to get a message without giving ack: channel.BasicGet(queueName, noAck)

I hope this can help you to move towards a full and reliable solution!

like image 42
Pietro Martinelli Avatar answered Mar 22 '26 11:03

Pietro Martinelli



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!