Spring AMQP exception handling basics

血红的双手。 提交于 2019-12-08 00:57:19

问题


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.


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!