在 WSO2 ESB 4.7.0 中,我们可以在接收序列中进行 JMS 回滚吗? [英] In WSO2 ESB 4.7.0 can we do JMS rollback in receiving sequence?

查看:19
本文介绍了在 WSO2 ESB 4.7.0 中,我们可以在接收序列中进行 JMS 回滚吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 WSO2 ESB 4.7.0 中为 Apache ActiveMQ 配置了事务和 CLIENT_ACKNOWLEDGE.axis2.xml 配置是:

I have configured Apache ActiveMQ with transaction and CLIENT_ACKNOWLEDGE in WSO2 ESB 4.7.0. The axis2.xml config is :

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

我有一个简单的带 jms 传输的直通代理,它将 JMS 队列中的消息传递给 jax-rs 服务.代理代码是:

I have a simple passthrough proxy with jms transport which passes the messages in the JMS queue to a jax-rs service. The proxy code is :

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
   name="MediaMoveQueue"
   transports="jms"
   startOnLoad="true"
   trace="enable">
<description/>
<target>
  <inSequence>
     <property name="messageType" value="application/json" scope="axis2"/>
     <property name="ContentType" value="application/json" scope="axis2"/>
     <send receive="JmsRollbackSequence">
        <endpoint>
           <address uri="http://192.168.1.2:9766/RestMediaMove_1.0.0/services/rest_media_move_i_f/restmediamoveif/hello"/>
        </endpoint>
     </send>

     <log level="custom">
        <property name="In MediaMoveQueue JMSERROR"
                  expression="get-property('JMSERROR')"/>
     </log>


     <switch source="get-property('JMSERROR')">
        <case regex="true">
           <property name="SET_ROLLBACK_ONLY" value="true" scope="axis2"/>
           <log level="custom">
              <property name="In MediaMoveQueue Transaction Action"
                        value="Rollbacked"/>
           </log>
        </case>
        <case regex="false">
           <log level="custom">
              <property name="In MediaMoveQueue Transaction Action"
                        value="Committed"/>                  
           </log>
         </case>
         <default>
           <property name="SET_ROLLBACK_ONLY" value="true" scope="axis2"/>
           <log level="custom">
              <property name="In MediaMoveQueue Transaction Action default"
                        value="Rollbacked"/>
           </log>
        </default>
     </switch>
  </inSequence>
  <outSequence>
     <log level="full">
        <property name="test" value="IN outsequence"/>
     </log>
     <send/>
  </outSequence>
</target>
<parameter name="transport.jms.ContentType">
  <rules>
     <jmsProperty>contentType</jmsProperty>
     <default>application/json</default>
  </rules>
</parameter>
</proxy>

JmsRollbackSequence 序列接收来自 jax-rs 服务的回复,根据返回的回复成功或失败,我想回滚 JMS 事务.但是如果我设置属性在 JmsRollbackSequence 中它绝对没有效果(我在使用下面显示的序列之前先尝试过).事务永远不会回滚.只有在 inSequence 中设置了该属性时,回滚才有效.这是 JmsRollbackSequence 的代码:

The JmsRollbackSequence sequence receives the reply from the jax-rs service and depending on the reply success or failure returned, I would like to rollback the JMS transaction. But if I set the property in the JmsRollbackSequence it has absolutely no effect ( I tried it first before using the sequence shown below). The transaction is never rolled back. The rollback works only if the property is set in the inSequence. Here is the code for the JmsRollbackSequence :

<?xml version="1.0" encoding="UTF-8"?>
<sequence xmlns="http://ws.apache.org/ns/synapse" name="JmsRollbackSequence">
<property name="JMSERROR" value="true"/>
    <log level="full">
      <property name="test" value="IN JmsRollbackSequence"/>
     </log>

</sequence>

所以我尝试在 JmsRollbackSequence 中设置一个名为 JMSERROR 的属性,并在 inSequence 中的发送中介之后读取它,我认为我可以回滚 inSequence 中的事务.但这也不起作用.inSequence 中的 switch case 是在 JmsRollbackSequence 中设置属性之前调用的,所以当我阅读它时,它总是返回 null.

So I tried to set up a property called JMSERROR in the JmsRollbackSequence and by reading it after the send mediator in the inSequence I thought I can roll back the transaction in the inSequence. But this does not work either. The switch case in inSequence is called before the property is set up in JmsRollbackSequence so when I read it it always returns null.

所以我的问题是:

1) 我们可以设置吗

<property name="SET_ROLLBACK_ONLY" value="true" scope="axis2"/>

按顺序?为什么在 JmsRollbackSequence 中不起作用?

in a sequence? Why does it not work in JmsRollbackSequence?

2) 由于中介应该是按顺序调用的,为什么 inSequence 中的 switch case 在 JmsRollbackSequence 有机会读取回复并设置 JMSERROR 属性之前运行?

2) As mediators are supposed to be called sequentially, why does the switch case in inSequence run before the JmsRollbackSequence has a chance to read the reply and set up the JMSERROR property?

推荐答案

我相信您只能从同一序列或与之关联的故障序列中控制事务.但是 WSO2 文档并没有真正说明这一点......

I believe you can only control a transaction from within the same sequence or the fault sequence associated with it. But the WSO2 documentation doesn't really say anything about this...

关于您的第二个问题:send 中介者是非阻塞,即以下中介者将在发送中介者返回之前执行.如果您希望它等待响应,则需要改用 callout 中介.然后,您可以评估响应并在需要时进行回滚(全部在 inSequence 中).

Regarding your second question: The send mediator is non-blocking, i.e. the following mediators will be executed before the send mediator has returned. If you want it to wait for the response, then you need to use the callout mediator instead. Then you can evaluate the response and do the rollback if needed (all inside the inSequence).

这篇关于在 WSO2 ESB 4.7.0 中,我们可以在接收序列中进行 JMS 回滚吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆