使用Apache Camel中的Transaction在直接路径上共享JMS deadLetterChannel

时间:2019-06-25 05:31:48

标签: java apache-camel jms spring-transactions spring-jms

我有一个骆驼路由,它从jboss JMS队列中读取发送到拖曳直接路由的消息,其中一个直接路由成功处理了该消息并发送到另一个JMS队列,另一个直接路由未能处理该消息。

我的期望是将原始交换移至死信通道,并且不应使用回滚来提交第一个直接路由将消息发送到JMS队列。

我尝试了许多可能性,但没有成功。下面我提供了骆驼路线。请帮助我。

 <bean id="jmsConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiTemplate" ref="jndiTemplate"/>
        <property name="jndiName" value="jms/RemoteConnectionFactory"/>
    </bean>

    <bean id="jmsTransactionManager" class="org.springframework.jms.connection.JmsTransactionManager">
        <property name="connectionFactory" ref="jmsConnectionFactory"/>
    </bean>

    <bean id="jmsConfig" class="org.apache.camel.component.jms.JmsConfiguration">
        <property name="connectionFactory" ref="jmsConnectionFactory"/>
    </bean>

    <bean id="jmsConfigTx" class="org.apache.camel.component.jms.JmsConfiguration">
        <property name="connectionFactory" ref="jmsConnectionFactory"/>
        <property name="transactionManager" ref="jmsTransactionManager"/>
        <property name="transacted" value="true"/>
    </bean>

    <bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
        <property name="configuration" ref="jmsConfig"/>
    </bean>

    <bean id="jmstx" class="org.apache.camel.component.jms.JmsComponent">
        <property name="configuration" ref="jmsConfigTx"/>
    </bean>

    <bean id="successProcessor" class="com.test.SuccessTestProcessor"/>
    <bean id="errorProcessor" class="com.test.ErrorTestProcessor"/>
    <bean id="deadChannelProcessor" class="com.test.DeadChannelTestProcessor"/>

    <bean id="myDeadLetterErrorHandler" class="org.apache.camel.builder.DeadLetterChannelBuilder">
        <property name="deadLetterUri" value="direct:error_channel"/>
    </bean>

    <camelContext xmlns="http://camel.apache.org/schema/spring">
        <route id="route-one" errorHandlerRef="myDeadLetterErrorHandler">
            <from uri="jmstx:queue:JMS_IN"/>
            <transacted/>
            <to uri="direct:success-route"/>
            <to uri="direct:error-route"/>
        </route>

        <route id="direct-success-route">
            <from uri="direct:success-route"/>
            <process ref="successProcessor"/>
            <to uri="jmstx:queue:JMS_OUT_1"/>
        </route>

        <route id="direct-error-route">
            <from uri="direct:error-route"/>
            <process ref="errorProcessor"/>
            <to uri="jmstx:queue:JMS_OUT_2"/>
        </route>

        <route id="direct_error_channel">
            <from uri="direct:error_channel"/>
            <process ref="deadChannelProcessor"/>
            <to uri="jmstx:queue:ERROR"/>
        </route>
    </camelContext>

1 个答案:

答案 0 :(得分:1)

<-- error -->

<bean id="jmsConfigTx" class="org.apache.camel.component.jms.JmsConfiguration">
    <property name="connectionFactory" ref="jmsConnectionFactory"/>
    <property name="transactionManager" ref="jmsTransactionManager"/>
    <property name="transacted" value="true"/>
</bean>

in the above code snippet  already Transactionfactory refers to the jmsConnectionFactory internally , is there any need to write one more property to refer jmsConnectionFactory .