2016-05-13 99 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功能,您不必在操作中維護會話。

感謝