Glide
Glide

Reputation: 21245

How to use Spring AMQP to read messages in a queue?

Given a queue that has messages, how do I use Spring AMQP get all the messages stored in that queue? Note, the question to not asking how to listen to a queue.

Upvotes: 2

Views: 2380

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121177

Sorry, I don't see any sense in such a solution. It is really better to listen to the queue for all messages. If you need something like browse - get and requeue (or nack), then yes AmqpTemplate.receive() is good choice. You should wrap that invocation to the TX (e.g. just with RabbitTransactionManager), do while(true) until receive() returns messages and TransactionAspectSupport.currentTransactionStatus().setRollbackOnly() in the end.

Upvotes: 2

Related Questions