How to correctly ack AMQP messages after the HTTP request completed

Question!

I have a controller method consuming messages from a AMQP queue - but I do not want to acknowledge those messages until I am sure as possible that the client that did the http request got the data (so that no data gets lost in case the http request would fail after leaving the controller method).

So far what I have been able to find is that you can use Spring interceptors to implement the "afterCompletion" which would be called after the request has been successfully completed. But this feels like overkill?



Answers

You can acknowledge after your http request has been completed by putting the code to acknowledge below that http call... like if exception occurs than don't acknowledge else acknowledge

channel.basicAck(DeliveryTag, false);


This video can help you solving your question :)
By: admin