JMS事务回滚属性在WSO2 4.8.1 ESB中不起作用

时间:2014-11-18 11:46:17

标签: transactions jms wso2 wso2esb

我做了一个简单的代理服务,它从JMS队列(基于ActiveMQ)监听XML消息并对其进行一些转换。我想实现JMS Transaction Rollback属性,因此如果在转换过程中发生任何错误或异常,则消息将为RollBack。

问题:

我已按照official说明操作,但无效。发生任何异常时,消息将不会回滚。记录异常但消息丢失。

代理服务SourceCode:

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="JMSGateway"
       transports="jms"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
   <target>
      <inSequence>
         <property name="OUT_ONLY" value="true"/>
         <log level="full"/>
         <xslt key="conf:/xslt/ConvertToCDM.xslt">
            <resource location="conf:xslt/ConvertToCDM.xslt" key="ConvertToCDM"/>
         </xslt>
         <log level="full"/>
         <log/>

      </inSequence>
      <outSequence/>
      <faultSequence>
         <property name="SET_ROLLBACK_ONLY" value="true" scope="axis2"/>
         <log level="custom">
            <property name="ERROR_CODE" expression="get-property('ERROR_CODE')"/>
            <property name="ERROR_MESSAGE" expression="get-property('ERROR_MESSAGE')"/>
            <property name="ERROR_DETAIL" expression="get-property('ERROR_DETAIL')"/>
            <property name="ERROR_EXCEPTION" expression="get-property('ERROR_EXCEPTION')"/>
            <property name="File_Name" expression="get-property('Received.File.Name')"/>
            <property name="Transaction Action" value="Rollbacked"/>
         </log>

      </faultSequence>
   </target>
   <parameter name="transport.jms.ContentType">
      <rules>
         <jmsProperty>contentType</jmsProperty>
         <default>application/xml</default>
      </rules>
   </parameter>
   <parameter name="transport.jms.ConnectionFactory">myQueueConnectionFactory</parameter>
   <parameter name="transport.jms.DestinationType">queue</parameter>
   <parameter name="transport.jms.Destination">CDMRequest</parameter>
   <description/>
</proxy>

1 个答案:

答案 0 :(得分:1)

您应该将thoses参数添加到代理def:

<parameter name="transport.jms.SessionAcknowledgement">CLIENT_ACKNOWLEDGE</parameter>
<parameter name="transport.jms.SessionTransacted">true</parameter>

如果您可以多次查看错误日志,则ActiveMQ已重新传递该消息,并且您知道您的ESB配置正确(使用SET_ROLLBACK_ONLY = true回滚有效)

几次之后,根据ActiveMQ conf,应该从队列中删除该消息并将其移至死信队列。

如果邮件丢失,您应该查看ActiveMQ配置(请参阅http://activemq.apache.org/message-redelivery-and-dlq-handling.html

您可以关注以下事实:非持久性消息不会发送到DLQ但会被删除。如果要更改此行为,请修改ActiveMQ conf:

<broker...>
  <destinationPolicy>
   <policyMap>
     <policyEntries>
       <!-- Set the following policy on all queues using the '>' wildcard -->
       <policyEntry queue=">">
         <!-- 
           Tell the dead letter strategy to also place non-persisted messages 
           onto the dead-letter queue if they can't be delivered.
         -->
         <deadLetterStrategy>
           <sharedDeadLetterStrategy processNonPersistent="true" />
         </deadLetterStrategy>
       </policyEntry>
     </policyEntries>
   </policyMap>
  </destinationPolicy>
...
</broker>