Reputation: 11
We have a job which will run at only End of day. During EOD it will read all the messages from RabbitMQ and generate a file. After a successful file generation we need to delete all the messages in RabbitMQ. Is there a way to do it from Java code?
We are using channel.basicGet(QueueName,false);
If I pass autoAck
as true instead of false then it will delete the messages but if there is any exception while processing then message will be lost.
To overcome this I used channel.queuepurge(QueueName);
but it is not working.
So our requirement is we need to read the messages from queue generate a file after successful file generation then we need to delete all messages else If any failures during processing then we should not delete the messages from queue
Upvotes: 0
Views: 1841
Reputation: 647
Use RabbitAdmin to purge the queue . Note the difference between purging and deleting .
Delete - Delete the queue
Purge - Empty the message of the queue.
@Autowired private RabbitAdmin admin;
...
admin.purgeQueue("queueName", false);
Upvotes: 1