apache camel jms组件中的exceptionListener和错误处理程序,对我不起作用

时间:2014-05-13 22:02:16

标签: jms apache-camel

我使用apache camel Jms组件使用下面的代码和配置连接到IBM MQ。当MQ管理器在消息轮询时因任何原因而关闭或在camel路由启动时关闭,我的errorHandler或exceptionListener不会被调用。

jmsComponenet = JmsComponent.jmsComponentAutoAcknowledge((ConnectionFactory) obj);
camelContext.addComponent("ibm-mq", jmsComponenet);
camelContext.addRoutes(new RouteBuilder() {
   @Override
   public void configure() throws Exception {
    from("ibm-mq:queue:PE_OUTBOUND?concurrentConsumers=5&exceptionListener=#exceptionListener&errorHandler=#errorHandler").to(
                            "mqprocessor"); 
   }

});

Spring Application-Context:

<bean id="exceptionListener" class="com.*****.JMSExceptionListener" />
<bean id="errorHandler" class="com.*****.JMSConnectionErrorHandler" />

classess实现了必需的接口

javax.jms.ExceptionListenerorg.springframework.util.ErrorHandler

尽管指定了Handler和Listener,但只记录了MQ Connection错误,因为日志和控制中的WARN消息没有到达这些类。

我在这里丢失/做错了什么?

这是DEBUG日志 -

11:18:20,783 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] (http-localhost/127.0.0.1:8080-1) Returning cached instance of singleton bean 'errorHandler'
11:18:20,784 DEBUG [org.apache.camel.util.IntrospectionSupport] (http-localhost/127.0.0.1:8080-1) Configured property: errorHandler on bean: org.apache.camel.component.jms.JmsConfiguration@17b86db4 with value: com.manh.processors.JMSConnectionErrorHandler@4d2a5096
11:18:20,784 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] (http-localhost/127.0.0.1:8080-1) Returning cached instance of singleton bean 'exceptionListener'
11:18:20,784 DEBUG [org.apache.camel.util.IntrospectionSupport] (http-localhost/127.0.0.1:8080-1) Configured property: exceptionListener on bean: org.apache.camel.component.jms.JmsConfiguration@17b86db4 with value: com.manh.processors.JMSExceptionListener@6c8b8e49
11:18:20,785 DEBUG [org.apache.camel.spring.SpringCamelContext] (http-localhost/127.0.0.1:8080-1) ibm-mq://queue:PE_OUTBOUND?concurrentConsumers=5&errorHandler=%23errorHandler&exceptionListener=%23exceptionListener converted to endpoint: Endpoint[ibm-mq://queue:PE_OUTBOUND?concurrentConsumers=5&errorHandler=%23errorHandler&exceptionListener=%23exceptionListener] by component: org.apache.camel.component.jms.JmsComponent@fb03c67
11:18:20,785 TRACE [org.apache.camel.management.DefaultManagementLifecycleStrategy] (http-localhost/127.0.0.1:8080-1) Checking whether to register Endpoint[ibm-mq://queue:PE_OUTBOUND?concurrentConsumers=5&errorHandler=%23errorHandler&exceptionListener=%23exceptionListener] from route: null

2 个答案:

答案 0 :(得分:2)

默认testConnectionOnStartup = false。我将它设置为ture并在启动路由时获得异常。

只有在处理消息时发生异常时,ErrorHandler才会起作用。

感谢你帮助Daniel。

答案 1 :(得分:0)

当找不到错误处理程序时,使用警告消息进行日志记录是默认的,因此我怀疑Camel无法找到提供的bean的实例。尝试将camel日志级别设置为调试并查看路由启动时的内容,我会期望某种消息说无法找到引用的bean。