How to do database transaction rollback in wso2 esb or wso2 dss

我的梦境 提交于 2019-12-11 10:53:35

问题


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


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/37203533/how-to-do-database-transaction-rollback-in-wso2-esb-or-wso2-dss

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!