2014-01-15 35 views
2

我正在使用wso2dss3.0.1和wso2esb4.8.0.I希望使用交易爲我啓用box_carying在wso2dss和它的工作正常。我希望插入數據到2表如果第二個表失敗我的第一個表還需要rollback.This功能在wso2dss.While工作我打電話使用wso2esb那時事務回滾相同的服務無法正常工作box_carying不精的工作我的配置是這樣的Wso2Dss Box_Carring不能在WSO2esb4.8.0中工作

<?xml version="1.0" encoding="UTF-8"?> 
<proxy xmlns="http://ws.apache.org/ns/synapse" 
     name="TransactionProxy" 
     transports="https,http" 
     statistics="disable" 
     trace="disable" 
     startOnLoad="true"> 
    <target> 
     <inSequence> 
     <log level="full"> 
      <property name="M1" value="*************HITTING Transaction PROXY*************"/> 
     </log> 
     <property name="OUT_ONLY" value="true"/> 
     <property name="companycode" expression="//companycode/text()"/> 
     <property name="companyname" expression="//companyname/text()"/> 
     <property name="clientcode" expression="//clientcode/text()"/> 
     <property name="clientname" expression="//clientname/text()"/> 
     <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/> 
       </soapenv:Envelope> 
      </format> 
      <args/> 
     </payloadFactory> 
     <log level="full"> 
      <property name="M2" value="*************HITTING Transaction PROXY*************"/> 
     </log> 
     <header name="Action" value="urn:begin_boxcar"/> 
     <callout serviceURL="http://192.168.1.201:9764/services/Transaction/begin_boxcar" 
        action="urn:begin_boxcar"> 
      <source type="envelope"/> 
      <target xmlns:s12="http://www.w3.org/2003/05/soap-envelope" 
        xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/" 
        xpath="s11:Body/child::*[fn:position()=1] | s12:Body/child::*[fn:position()=1]"/> 
     </callout> 
     <payloadFactory media-type="xml"> 
      <format> 
       <p:insertinto_mclient_OP xmlns:p="http://ws.wso2.org/dataservice"> 
        <xs:clientcode xmlns:xs="http://ws.wso2.org/dataservice">$1</xs:clientcode> 
        <xs:clientname xmlns:xs="http://ws.wso2.org/dataservice">$2</xs:clientname> 
        <xs:createdbyid xmlns:xs="http://ws.wso2.org/dataservice">-1</xs:createdbyid> 
        <xs:modifiedbyid xmlns:xs="http://ws.wso2.org/dataservice">-1</xs:modifiedbyid> 
       </p:insertinto_mclient_OP> 
      </format> 
      <args> 
       <arg evaluator="xml" expression="get-property('clientcode')"/> 
       <arg evaluator="xml" expression="get-property('clientname')"/> 
      </args> 
     </payloadFactory> 
     <header name="Action" value="urn:insertinto_mclient_OP"/> 
     <callout serviceURL="http://192.168.1.201:9764/services/Transaction/" 
        action="urn:insertinto_mclient_OP"> 
      <source xmlns:s12="http://www.w3.org/2003/05/soap-envelope" 
        xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/" 
        xpath="s11:Body/child::*[fn:position()=1] | s12:Body/child::*[fn:position()=1]"/> 
      <target xmlns:s12="http://www.w3.org/2003/05/soap-envelope" 
        xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/" 
        xpath="s11:Body/child::*[fn:position()=1] | s12:Body/child::*[fn:position()=1]"/> 
     </callout> 
     <payloadFactory media-type="xml"> 
      <format> 
       <p:insertinto_mcompany_OP xmlns:p="http://ws.wso2.org/dataservice"> 
        <xs:companycode xmlns:xs="http://ws.wso2.org/dataservice">$1</xs:companycode> 
        <xs:comapnyname xmlns:xs="http://ws.wso2.org/dataservice">$2</xs:comapnyname> 
        <xs:createdbyid xmlns:xs="http://ws.wso2.org/dataservice">-1</xs:createdbyid> 
        <xs:modifiedbyid xmlns:xs="http://ws.wso2.org/dataservice">-1</xs:modifiedbyid> 
        <xs:clientid xmlns:xs="http://ws.wso2.org/dataservice">-1</xs:clientid> 
       </p:insertinto_mcompany_OP> 
      </format> 
      <args> 
       <arg evaluator="xml" expression="get-property('companycode')"/> 
       <arg evaluator="xml" expression="get-property('companyname')"/> 
      </args> 
     </payloadFactory> 
     <log level="full"> 
      <property name="M5" value="**************hitting2nd dss*****"/> 
     </log> 
     <header name="Action" value="urn:insertinto_mcompany_OP"/> 
     <callout serviceURL="http://192.168.1.201:9764/services/Transaction/" 
        action="urn:insertinto_mcompany_OP"> 
      <source xmlns:s12="http://www.w3.org/2003/05/soap-envelope" 
        xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/" 
        xpath="s11:Body/child::*[fn:position()=1] | s12:Body/child::*[fn:position()=1]"/> 
      <target xmlns:s12="http://www.w3.org/2003/05/soap-envelope" 
        xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/" 
        xpath="s11:Body/child::*[fn:position()=1] | s12:Body/child::*[fn:position()=1]"/> 
     </callout> 
     <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/> 
       </soapenv:Envelope> 
      </format> 
      <args/> 
     </payloadFactory> 
     <log level="full"> 
      <property name="M3" value="*************HITTING Transaction PROXY*************"/> 
     </log> 
     <header name="Action" value="urn:end_boxcar"/> 
     <callout serviceURL="http://192.168.1.201:9764/services/Transaction/end_boxcar" 
        action="urn:end_boxcar"> 
      <source type="envelope"/> 
      <target xmlns:s12="http://www.w3.org/2003/05/soap-envelope" 
        xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/" 
        xpath="s11:Body/child::*[fn:position()=1] | s12:Body/child::*[fn:position()=1]"/> 
     </callout> 
     <log level="full"> 
      <property name="M4" value="*************HITTING Transaction PROXY*************"/> 
     </log> 
     </inSequence> 
     <outSequence> 
     <send/> 
     </outSequence> 
    </target> 
    <description/> 
</proxy> 

如果我發送正確的值到數據庫這些值存儲在表格中,但如果我發送錯誤的數據到第二張表,即使我的第一張表存儲數據第二是錯誤的。這裏沒有發生Box_carrying是這個版本錫永錯誤的東西工作正常,則Y不是從wso2esb雙方else.where從wso2dss嘗試,它的工具交易我跟着這個鏈接 在這裏輸入鏈接的描述 enter link description here 謝謝進階..

+0

嗨,正如你所說,當你直接在WSO2 DSS調用服務boxcarring工作正常。這意味着你在代理配置中有問題。我沒有徹底解決。你可以嘗試使用TcpMon監視消息,看看有什麼不同嗎?您可以在WSO2 DSS上使用SoapUI進行直接服務調用。 –

+0

你有沒有看到發佈的代碼?我開始與begin_boxcar和end_boxcar.BUt結束,而我這樣做與dss如果我開始begin_boxcar然後第一次插入之後,我檢查了表,但沒有數據插入,如果我插入到第二個表,並end_boxcar結束,然後只有數據插入到2表。當我檢查與上述代理服務配置與begin_boxcar插入並插入第一個表和檢查表dat是否有意味着與end_boxcar也插入數據正確 – Faisal

回答

1

你你沒有做你的DSS在同一會話中的操作。

DSS使用JSESSIONID cookie來識別會話。您需要從begin_boxcar調用中獲取該cookie,然後將該cookie與您希望在同一事務中執行的其餘DSS調用一起發送。

最後,您需要在呼叫中發送相同的cookie到end_boxcarabort_boxcar,無論您最終打給誰。

您在DSS服務,您可以通過傳輸特性訪問由服務設置的cookie呼叫到begin_boxcar操作後:

<property name="setCookieHeader" expression="$trp:Set-Cookie" action="set"/> 

之後,你有在突觸消息上下文屬性中的cookie,你可以使用腳本語言,比如Groovy或JavaScript解析Cookie中的實際值。

任何後續調用DSS應該是在同一個boxcarring會話必須的cookie發送給DSS服務。你可以有Axis2的將其設置爲一個傳輸性能(類似於在這種情況下,HTTP頭)發送cookie:

<property name="Cookie" expression="$ctx:jsessionIdCookie" action="set" scope="transport" /> 
+0

你見過發表的代碼?我開始與begin_boxcar和end_boxcar.BUt結束,而我這樣做與dss如果我開始begin_boxcar然後第一次插入之後,我檢查了表,但沒有數據插入,如果我插入到第二個表,並end_boxcar結束,然後只有數據插入到2個表中。當我檢查代理服務配置像上面一樣,用begin_boxcar插入並插入第一個表並檢查表dat是否存在與end_boxcar也意味着數據插入不正確 – Faisal

+0

如何將DSS會話插入到代理中。這是什麼JSESSIONID – Faisal

+0

它不起作用給null。 <標註的serviceURL = 「HTTP:// lovcalgos:9764 /服務/交易/ begin_boxcar」 行動= 「甕:begin_boxcar」> <源類型= 「信封」/> <屬性名= 「setCookieHeader」 表達式=「$ trp:Set-Cookie」 scope =「default」 type =「STRING」/> Faisal

0

有一種變通方法,使用request_box在單個請求包裹多個SQL非查詢操作避免使用會話。如果請求任何SQL失敗,整個請求將被回滾。

首先,你需要名爲mydb與用戶名爲root其密碼爲root和PostgreSQL數據庫也名爲mydb與用戶叫postgres,其密碼爲root mysql數據庫。 然後在兩個數據庫中創建一個名爲客戶表:

CREATE TABLE customer (
     cust_id int(11) NOT NULL, 
     name varchar(255) NOT NULL, 
     PRIMARY KEY (`cust_id`) 
    ); 

樣品插入一條記錄到MySQL,然後插入兩個記錄具有相同的cust_id於Postgres這將導致一個錯誤,因此整個交易將回滾和你不會看到插入mysql的記錄。

下面是我的代理服務定義:

<?xml version="1.0" encoding="UTF-8"?> 
    <proxy xmlns="http://ws.apache.org/ns/synapse" name="MyTransactionProxy" 
     startOnLoad="true" statistics="disable" trace="disable" transports="http,https"> 
     <target> 
      <inSequence> 
       <property expression="//id/text()" name="id"/> 
       <property expression="//name/text()" name="name"/> 
       <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:request_box> 
            <dat:my_insert> 
             <dat:id>$1</dat:id> 
             <dat:name>$2</dat:name> 
            </dat:my_insert> 
            <dat:pos_insert> 
             <dat:id>$1</dat:id> 
             <dat:name>$2</dat:name> 
            </dat:pos_insert> 
            <dat:pos_insert> 
             <dat:id>$1</dat:id> 
             <dat:name>$2</dat:name> 
            </dat:pos_insert> 
           </dat:request_box> 
          </soapenv:Body> 
         </soapenv:Envelope> 
        </format> 
        <args> 
         <arg evaluator="xml" expression="get-property('id')"/> 
         <arg evaluator="xml" expression="get-property('name')"/> 
        </args> 
       </payloadFactory> 
       <callout action="urn:request_box" serviceURL="http://longqinsi:8280/services/DTPDS"> 
        <source xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/" 
         xmlns:s12="http://www.w3.org/2003/05/soap-envelope" 
         xpath="s11:Body/child::*[fn:position()=1] | s12:Body/child::*[fn:position()=1]"/> 
        <target xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/" 
         xmlns:s12="http://www.w3.org/2003/05/soap-envelope" 
         xpath="s11:Body/child::*[fn:position()=1] | s12:Body/child::*[fn:position()=1]"/> 
       </callout> 
      </inSequence> 
      <outSequence> 
       <send/> 
      </outSequence> 
     </target> 
     <description/> 
    </proxy> 

我的數據服務的定義如下:

<?xml version="1.0" encoding="UTF-8"?> 
    <data disableStreaming="true" enableBoxcarring="true" enableDTP="true" name="DTPDS"> 
     <config id="pos_ds"> 
      <property name="org.wso2.ws.dataservice.xa_datasource_class">org.postgresql.xa.PGXADataSource</property> 
      <property name="org.wso2.ws.dataservice.xa_datasource_properties"> 
       <property name="ServerName">localhost</property> 
       <property name="PortNumber">5432</property> 
       <property name="DatabaseName">MyDB</property> 
       <property name="User">postgres</property> 
       <property name="Password">root</property> 
      </property> 
     </config> 
     <config id="my_ds"> 
      <property name="org.wso2.ws.dataservice.xa_datasource_class">com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</property> 
      <property name="org.wso2.ws.dataservice.xa_datasource_properties"> 
       <property name="URL">jdbc:mysql://localhost:3306/MyDB</property> 
       <property name="User">root</property> 
       <property name="Password">root</property> 
      </property> 
     </config> 
     <query id="pos_q" useConfig="pos_ds"> 
      <sql>INSERT INTO customer VALUES(?,?)</sql> 
      <param name="id" sqlType="INTEGER"/> 
      <param name="name" sqlType="STRING"/> 
     </query> 
     <query id="my_q" useConfig="my_ds"> 
      <sql>INSERT INTO customer VALUES(?,?)</sql> 
      <param name="id" sqlType="INTEGER"/> 
      <param name="name" sqlType="STRING"/> 
     </query> 
     <operation disableStreaming="true" name="pos_insert" returnRequestStatus="true"> 
      <call-query href="pos_q"> 
       <with-param name="id" query-param="id"/> 
       <with-param name="name" query-param="name"/> 
      </call-query> 
     </operation> 
     <operation disableStreaming="true" name="my_insert" returnRequestStatus="true"> 
      <call-query href="my_q"> 
       <with-param name="id" query-param="id"/> 
       <with-param name="name" query-param="name"/> 
      </call-query> 
     </operation> 
    </data> 
+0

請使用代碼標籤正確編輯您的代碼。 – Sand

相關問題