I have a Listener class (that implements Spring's MessageListener
interface) where I need to not requeue any messages if an exception occurs, but I want to post the message to a different queue.
It seems like I need the Listener to catch an AmqpRejectAndDontRequeueException
, but I've read that I need it to throw the exception instead. If I do that, I can't re-post the message.
Should I just catch a plain Exception and do the re-post there? Is there any need to actually throw the AmqpRejectAndDontRequeueException
at that point?
I'm wondering about the best practice for this. Thanks.
There are different ways to achieve this.
Most simply, you just need to catch all the exception on the client side and throw a AmqpRejectAndDontRequeueException
.
Otherwise, have a look at FatalExceptionStrategy
, you need have your own strategy and let it always return true
来源:https://stackoverflow.com/questions/28245473/spring-amqp-exception-handling-basics