2016-05-13 55 views
1

我使用Box_caring功能插入到三个表中,插入正确发生,但是如果在插入到表中时发生某些错误,它将不会滚动备份数据。如何在wso2 esb或wso2中执行数据库事务回滚dss

我正在寻找解决方案来应对以下挑战:有一组相关的表格。它们通过主键/外键关系相关,需要更新/插入相关表中的对象。在迭代器中介体内插入/更新。当其中一个更新/插入失败时会发生什么?所有插入/更新的对象是否会回滚?

请给任何想法或链接或代码片段,使其工作。

注:我使用WSO2 ESB-4.8.1,WSO2 DSS-3.2.2和MSSQL数据库

通过下面的链接飘:提前 http://charithaka.blogspot.in/2014/02/common-mistakes-to-avoid-in-wso2-esb-1.html

How we can ROLLBACK the Transaction in WSO2DSS or WSO2ESB

感谢

回答

0

当您使用box_carring功能,你必须在所有的操作调用保持同一个会话。否则,它将评估为分离的调用,不会是原子的。以下是可用于维护同一会话的示例突触配置。

<?xml version="1.0" encoding="UTF-8"?> 
<proxy xmlns="http://ws.apache.org/ns/synapse" 
     name="ESBService" 
     transports="https http" 
     startOnLoad="true" 
     trace="disable"> 
    <description/> 
    <target> 
     <inSequence> 
     <transaction action="new"/> 
     <property name="id" expression="json-eval($.id)"/> 
     <property name="userName" expression="json-eval($.userName)"/> 
     <property name="firstName" expression="json-eval($.firstName)"/> 
     <property name="lastName" expression="json-eval($.lastName)"/> 
     <property name="address" expression="json-eval($.address)"/> 
     <enrich> 
      <source type="body" clone="true"/> 
      <target type="property" property="FirstBody"/> 
     </enrich> 
     <property name="messageType" value="application/xml" scope="axis2"/> 
     <header name="Action" value="urn:begin_boxcar"/> 
     <payloadFactory media-type="xml"> 
      <format> 
       <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
           xmlns:dat="http://ws.wso2.org/dataservice"> 
        <soapenv:Header/> 
        <soapenv:Body> 
        <dat:begin_boxcar/> 
        </soapenv:Body> 
       </soapenv:Envelope> 
      </format> 
      <args/> 
     </payloadFactory> 
     <call> 
      <endpoint> 
       <address uri="http://localhost:9764/services/testService.SOAP11Endpoint/"/> 
      </endpoint> 
     </call> 
     <property name="setCookieHeader" expression="$trp:Set-Cookie"/> 
     <property name="Cookie" 
        expression="get-property('setCookieHeader')" 
        scope="transport"/> 
     <property name="OUT_ONLY" value="true"/> 
     <payloadFactory media-type="xml"> 
      <format> 
       <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
           xmlns:dat="http://ws.wso2.org/dataservice"> 
        <soapenv:Header/> 
        <soapenv:Body> 
        <p:insert_employee xmlns:p="http://ws.wso2.org/dataservice"> 
         <xs:UserId xmlns:xs="http://ws.wso2.org/dataservice">$1</xs:UserId> 
         <xs:userName xmlns:xs="http://ws.wso2.org/dataservice">$2</xs:userName> 
         <xs:firstName xmlns:xs="http://ws.wso2.org/dataservice">$3</xs:firstName> 
         <xs:lastName xmlns:xs="http://ws.wso2.org/dataservice">$4</xs:lastName> 
        </p:insert_employee> 
        </soapenv:Body> 
       </soapenv:Envelope> 
      </format> 
      <args> 
       <arg evaluator="xml" expression="get-property('id')"/> 
       <arg evaluator="xml" expression="get-property('userName')"/> 
       <arg evaluator="xml" expression="get-property('firstName')"/> 
       <arg evaluator="xml" expression="get-property('lastName')"/> 
      </args> 
     </payloadFactory> 
     <property name="Content-Encoding" scope="transport" action="remove"/> 
     <property name="Cookie" 
        expression="get-property('setCookieHeader')" 
        scope="transport"/> 
     <call> 
      <endpoint> 
       <address uri="http://localhost:9764/services/testService.SOAP11Endpoint/"/> 
      </endpoint> 
     </call> 
     <payloadFactory media-type="xml"> 
      <format> 
       <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
           xmlns:dat="http://ws.wso2.org/dataservice"> 
        <soapenv:Header/> 
        <soapenv:Body> 
        <dat:end_boxcar/> 
        </soapenv:Body> 
       </soapenv:Envelope> 
      </format> 
      <args/> 
     </payloadFactory> 
     <property name="Content-Encoding" scope="transport" action="remove"/> 
     <property name="Cookie" 
        expression="get-property('setCookieHeader')" 
        scope="transport"/> 
     <call> 
      <endpoint> 
       <address uri="http://localhost:9764/services/testService.SOAP11Endpoint/"/> 
      </endpoint> 
     </call> 
     <respond/> 
     </inSequence> 
     <faultSequence> 
     <log> 
      <property name="END" value="****ROLLBACK****"/> 
     </log> 
     <transaction action="rollback"/> 
     <respond/> 
     </faultSequence> 
    </target> 
</proxy> 

但是,您可以使用request_box功能,您不必在操作中维护会话。

感谢