Reputation: 21245
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
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