如何使用IBM MQ为Apache Camel路由添加事务超时?

时间:2018-07-18 19:03:24

标签: apache-camel ibm-mq spring-transactions spring-jms camel-jms

我们在应用程序中遇到一个问题,即在ibm mq上提交jms消息需要花费数小时才能完成,这反过来导致ibm mq中的日志空间填满,并且JVM在应用程序端挂起了问题。为了解决这个问题,我尝试在路由,jms组件等上实现事务超时。但是似乎没有任何效果。

应用程序中有3条路线

  1. 阅读邮件(开始路线)
  2. 传递/发送消息
  3. 错误路由(发送到错误队列)

路线定义如下,

输入/消费路线

public class InputRoute extends SpringRouteBuilder {

    @Override
    public void configure() throws Exception {
    from("wmqInConsumer:{{mq.inputQueue}}?concurrentConsumers={{num.consumers}}&maxConcurrentConsumers={{max.num.consumers}}&defaultTaskExecutorType=ThreadPool&preserveMessageQos=true").routeId("input-route").setHeader("Message_Key").method("headerEnricher", "setKey").inOnly("direct:deliver-normal-route-1");
    }
}

传递路线

public class DeliverRoute extends SpringRouteBuilder {

    @Override
    public void configure() throws Exception {

        from("direct:deliver-normal-route-1").transacted("PROPAGATION_REQUIRES_NEW").inOnly("direct:deliver-route-2");

        from("direct:deliver-route-2").process("myServicesProcessor").split()
                .method("messageSplitterBean", "splitMessage").shareUnitOfWork().stopOnException()
                .toD("wmqDeliverJms:${headers.Deliver}?preserveMessageQos=true");
    }
}

错误路线

public class ErrorRoute extends SpringRouteBuilder {

    @Override
    public void configure() throws Exception {

        from("direct:errorChannelRoute").transacted("PROPAGATION_REQUIRES_NEW").inOnly("direct:errorChannelRoute-1");

        from("direct:errorChannelRoute-1").process("errorServicesProcessor").split()
                .method("messageSplitterBean", "splitErrorMessage").shareUnitOfWork().stopOnException()
                .toD("wmqDeliverJms:${headers.Deliver}?preserveMessageQos=true");

    }
}

这是我根据Camel文档尝试的事务超时。但是它不起作用,我也看不到跟踪日志中也发生事务超时。同样,如果超时,则不确定消息将如何处理。它会进入错误队列或完全回滚以重试吗?

在输入路径上,transactionTimeout = 10

from("wmqInConsumer:{{mq.inputQueue}}?concurrentConsumers={{num.consumers}}&maxConcurrentConsumers={{max.num.consumers}}&defaultTaskExecutorType=ThreadPool&preserveMessageQos=true&transactionTimeout=10").routeId("input-route").setHeader("Message_Key").method("headerEnricher", "setKey").inOnly("direct:deliver-normal-route-1");

在输入路由JMS组件上,

<bean id="wmqInConsumer" class="org.apache.camel.component.jms.JmsComponent">
        <property name="connectionFactory" ref="myConnectionFactory" />
        <property name="transacted" value="true" />
        <property name="transactionTimeout" value="30"></property> -->
    </bean>

在“传递路由JMS组件”上,

<bean id="wmqDeliverJms" class="org.apache.camel.component.jms.JmsComponent">
        <property name="connectionFactory" ref="myConnectionFactory" />
        <property name="destinationResolver" ref="myJmsDestinationResolver" />
        <property name="transacted" value="true" />
        <property name="transactionTimeout" value="30"></property>
    </bean>

0 个答案:

没有答案