当我的进程在客户端成功完成时,如何在ActiveMQ中进行事务提交

时间:2018-01-15 10:37:30

标签: apache-camel activemq

<route>
        <from
            uri="jms:queue:inBox?concurrentConsumers=20" />

        <camel:process ref="processor1" />
        <transacted/>
        <camel:process ref="Processor2" />
    </route>

一旦我的处理器2成功,则收件箱队列必须从activeMQ中取消队列消息。目前它正在JMS端点上出列消息。

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


<bean id="jmsConnectionFactory"
    class="com.mypackage.EncryptionAwareActiveMQConnectionFactory">
    <property name="brokerURL" value="tcp://localhost:61616" />
    <property name="userName" value="admin" />
    <property name="password" value="@PASSWORD@" />
</bean>


<bean id="pooledConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory"
    init-method="start" destroy-method="stop">
    <property name="maxConnections" value="20" />
    <property name="connectionFactory" ref="jmsConnectionFactory" />
</bean>


<bean id="jmsConfig" class="org.apache.camel.component.jms.JmsConfiguration">
    <property name="connectionFactory" ref="pooledConnectionFactory" />
    <property name="concurrentConsumers" value="50" />
    <property name="deliveryPersistent" value="true" />
    <property name="transacted" value="true" />
    <property name="transactionManager" ref="jmsTransactionManager" />
</bean>


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

</bean>

所以我使用这样的配置并将transacted设置为true而且我还使用了JMS跨国经理。

1 个答案:

答案 0 :(得分:0)

仅将<transacted/>添加到您的路线是不够的。您还需要配置JMS组件以支持事务。

我建议你仔细阅读documentation。 以下是链接中的相关代码示例:

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

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

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

<bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
  <property name="brokerURL" value="vm://broker1?brokerConfig=xbean:tutorial/activemq.xml"/>
</bean>