【问题标题】:exceptionListener and errorHandler in apache camle jms component, not working for meapache camle jms组件中的exceptionListener和errorHandler,对我不起作用
【发布时间】:2014-05-13 22:02:16
【问题描述】:

我正在使用以下代码和配置使用 apache camel Jms 组件连接到 IBM MQ。当 MQ 管理器在消息轮询时因任何原因宕机或在骆驼路由启动时宕机时,我的 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 应用程序上下文:

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

类实现所需的接口

javax.jms.ExceptionListenerorg.springframework.util.ErrorHandler

尽管指定了处理程序和侦听器,但 MQ 连接错误只是在日志中记录为 WARN 消息,并且控制不会到达这些类。

我在这里遗漏/做错了什么?

这是调试日志-

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

【问题讨论】:

    标签: jms apache-camel


    【解决方案1】:

    默认 testConnectionOnStartup = false。我将其设置为 ture 并在路由启动时出现异常。

    ErrorHandler 仅在处理消息时发生异常时才起作用。

    感谢丹尼尔的帮助。

    【讨论】:

      【解决方案2】:

      当找不到错误处理程序时,默认记录带有警告消息,所以我怀疑 Camel 无法找到所提供 bean 的实例。尝试将骆驼日志级别设置为调试并查看路由启动时显示的内容,我希望出现某种消息,说明找不到引用的 bean。

      【讨论】:

      • 我在日志中没有看到任何 bean 引用错误。我在日志中看到了 Configured property: errorHandlerConfigured property: exceptionListener 配置。我在上面的问题部分添加了完整的日志。
      • 实际的 WARN 消息是什么样的?
      • 14:30:51,249 WARN [org.apache.camel.component.jms.DefaultJmsMessageListenerContainer](Camel (CamelContext) 线程 #3 - JmsConsumer[PE_OUTBOUND]) 目标的 JMS 消息侦听器调用程序设置失败'PE_OUTBOUND' - 试图恢复。原因:JMSWMQ2002:无法从目标“PE_OUTBOUND”获取消息。;嵌套异常是 com.ibm.mq.MQException: JMSCMQ0001: WebSphere MQ call failed with compcode '2' ('MQCC_FAILED') reason '2202' ('MQRC_CONNECTION_QUIESCING')。:
      • 错误处理程序和异常处理程序特定于您的路线。我感觉你的异常在调用实际路由之前被抛出,这就是为什么你指定的处理程序永远不会被调用。
      • 默认 testConnectionOnStartup = false。我将其设置为 ture 并在路由启动时出现异常。只有在处理消息时发生异常时,ErrorHandler 才会发挥作用。谢谢丹尼尔的帮助。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-23
      • 1970-01-01
      • 1970-01-01
      • 2020-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多