mstrom
mstrom

Reputation: 1743

Spring AMQP exception handling basics

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.

Upvotes: 2

Views: 2936

Answers (1)

Jaiwo99
Jaiwo99

Reputation: 10017

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

Upvotes: 4

Related Questions