【问题标题】:Wso2Dss Box_Carring not working in WSO2esb4.8.0Wso2Dss Box_Carring 在 WSO2esb4.8.0 中不起作用
【发布时间】:2014-02-03 19:24:43
【问题描述】:

我正在使用 wso2dss3.0.1 和 wso2esb4.8.0。我希望使用事务,因为我在 wso2dss 中启用了 box_carying 并且它工作正常。意味着如果第二个表也失败了我的第一个表,我希望将数据插入到 2 个表中需要回滚。此功能在 wso2dss 中工作。当我使用 wso2esb 调用相同的服务时,事务回滚不起作用 box_carying 无法正常工作,我的配置是这样的

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

如果我向 db 发送正确的值,这些值可以很好地存储在表中,但是如果我将错误的数据发送到第二个表中,即使我的第一个表存储数据第二个出错了。这里 Box_carrying 没有发生,这个版本错误是什么别的。从 wso2dss try-it 工具交易工作正常然后 y 不是来自 wso2esb 方面我遵循了这个链接 在此处输入链接描述 enter link description here 感谢Adv..

【问题讨论】:

  • 您好,正如您所说,当您直接在 WSO2 DSS 上调用服务时,boxcarring 工作正常。这意味着您在代理配置中有问题。我没有彻底看完。您可以尝试使用 TcpMon 监控消息,看看有什么不同吗?您可以使用 SoapUI 在 WSO2 DSS 上直接调用服务。
  • 你看过已发布的代码吗?我从 begin_boxcar 开始并以 end_boxcar.BUt 结束,而我使用 dss 执行此操作,如果我从 begin_boxcar 开始,然后第一次插入,然后我检查了表,但如果我插入到第二个表并以 end_boxcar 结束,则没有数据插入然后只有数据插入到 2 个表中。当我使用上面的代理服务配置进行检查时,使用 begin_boxcar 并插入了第一个表并检查了表 dat 是否意味着没有 end_boxcar 也正确插入了数据

标签: transactions wso2 axis2 wso2esb wso2dss


【解决方案1】:

您没有在同一会话中执行 DSS 操作。

DSS 使用JSESSIONID cookie 来识别会话。您需要从 begin_boxcar 调用中获取该 cookie,然后将 cookie 与您希望在同一事务中执行的其余 DSS 调用一起发送。

最后,您需要在调用中将相同的 cookie 发送到 end_boxcarabort_boxcar,无论您最终调用哪个。

在 DSS 服务中调用 begin_boxcar 操作后,您可以通过传输属性访问服务设置的 cookie:

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

在 Synapse 消息上下文属性中拥有 cookie 后,您可以使用 Groovy 或 JavaScript 等脚本语言来解析 cookie 中的实际值。

应该在同一个 boxcarring 会话中的任何后续 DSS 调用都必须将 cookie 发送到 DSS 服务。您可以让 Axis2 通过将 cookie 设置为传输属性(在这种情况下类似于 HTTP 标头)来发送 cookie:

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

【讨论】:

  • 你看过已发布的代码吗?我从 begin_boxcar 开始并以 end_boxcar.BUt 结束,而我使用 dss 执行此操作,如果我从 begin_boxcar 开始,然后第一次插入,然后我检查了表,但如果我插入到第二个表并以 end_boxcar 结束,则没有数据插入然后只有数据插入到 2 个表中。当我使用上面的代理服务配置进行检查时,使用 begin_boxcar 并插入了第一个表并检查了表 dat 是否意味着没有 end_boxcar 也正确插入了数据
  • 我怎样才能让 DSS 会话进入代理。这个 JSESSIONID 是什么
  • 它不工作给空。 lovcalgos:9764/services/Transaction/begin_boxcar" action="urn:begin_boxcar">
  • 我已经尝试过这个属性,即使这个也不起作用 这是laso not工作同样给 null
  • 本期有消息吗?我也面临同样的问题。
【解决方案2】:

有一个变通方法,使用request_box将多个sql非查询操作包装在一个请求中,避免使用session。如果请求中任何一条sql失败,整个请求都会回滚。

首先,您需要一个名为 MyDB 的 mysql 数据库,用户名为 root,其密码为 root,以及一个名为 MyDB 的 Postgresql 数据库,用户名为 postgres,其密码为 root。 然后在两个数据库中创建一个名为 customer 的表:

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

示例向mysql中插入一条记录,然后在postgres中插入两条cust_id相同的记录,这会导致错误,因此整个事务将被回滚,您将看不到插入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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-02
    • 1970-01-01
    • 1970-01-01
    • 2019-06-13
    • 1970-01-01
    相关资源
    最近更新 更多