How to do database transaction rollback in wso2 es

2019-08-12 18:38发布

I am inserting into three tables using Box_caring feature, insertion happening properly but if some error comes in between while inserting into tables its not roll backing the data.

I'm looking for a solution to the following challenge:Have a set of related tables. They are related by primary/foreign key relations and need to update/insert objects in the related tables. Insert/update happening inside iterator mediator. what happens when one of the updates/insert fails? Will all the inserted/updated objects rolled back?.

Please give any ideas or links or code snippet to make it work.

Note: Am using wso2 esb-4.8.1, wso2 dss-3.2.2 and MSSQL database

Gone through below links: 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

Thanks in advance

2条回答
够拽才男人
2楼-- · 2019-08-12 19:03

Here you have to implement Distributed XA transactions. Could you please refer to the article [1] which will guide you through this.

[1]https://docs.wso2.com/display/ESB490/Sample+657%3A+Distributed+Transaction+Management

查看更多
ゆ 、 Hurt°
3楼-- · 2019-08-12 19:22

When you are using box_carring feature, you have to maintain same session across all the operation calls. Otherwise, it will evaluates as separated calls and will not be atomic. Here is a sample synapse config that can be used to maintain the same session.

<?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>

However, you can use request_box feature, where you do not have to maintain the session across operations.

Thanks

查看更多
登录 后发表回答