java Spring JMS:为@JmsListener 注释方法设置 ErrorHandler
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40654586/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Spring JMS : Set ErrorHandler for @JmsListener annotated method
提问by faizi
I am using a @JmsListener
annotated method listen to JMS messages as shown below.
我正在使用带@JmsListener
注释的方法来监听 JMS 消息,如下所示。
@JmsListener(destination="exampleQueue")
public void fetch(@Payload String message){
process(message);
}
When this method execution result in an exception, I got a warn log
当此方法执行导致异常时,我收到警告日志
Execution of JMS message listener failed, and no ErrorHandler has been set.
How do I set an ErrorHandler
to handle the case. I am using spring boot 1.3.3.RELEASE
我如何设置一个ErrorHandler
来处理这个案例。我正在使用弹簧靴 1.3.3.RELEASE
回答by faizi
While using annotations like @EnableJms
, @JmsListener
etc to work with Spring JMS, the ErrorHandler can be set like this
虽然使用注释一样@EnableJms
,@JmsListener
等来的工作与Spring JMS的的ErrorHandler可以设置这样的
@Bean
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory(ConnectionFactory connectionFactory, ExampleErrorHandler errorHandler) {
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
factory.setConnectionFactory(connectionFactory);
factory.setErrorHandler(errorHandler);
return factory;
}
@Service
public class ExampleErrorHandler implements ErrorHandler{
@Override
public void handleError(Throwable t) {
//handle exception here
}
}
More details are available here : Annotation-driven listener endpoints
此处提供更多详细信息:注释驱动的侦听器端点