【问题标题】:How to link a soap request and response in mule 3如何在 mule 3 中链接肥皂请求和响应
【发布时间】:2012-01-15 20:29:15
【问题描述】:

我需要将文件发送到外部 Web 服务。当响应为1时,删除文件,否则保留文件。

我使用文件连接器发送文件,并在 Oracle 中插入一条记录。文件发送出去的时候,key就是文件connect的message id。我想保留消息 ID,以便在响应返回时使用此 ID 更新记录。

我尝试使用 MessagePropertiesTransformer 添加自定义属性,但响应没有保留它。有什么办法可以保留消息ID?

我的配置:

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns="http://www.mulesoft.org/schema/mule/core"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:file="http://www.mulesoft.org/schema/mule/file"
      xmlns:stdio="http://www.mulesoft.org/schema/mule/stdio"
      xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf"
      xmlns:spring="http://www.springframework.org/schema/beans"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:jdbc="http://www.mulesoft.org/schema/mule/jdbc"
      xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml"
      xsi:schemaLocation="
          http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/3.1/mule-file.xsd
          http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.1/mule.xsd
          http://www.mulesoft.org/schema/mule/stdio http://www.mulesoft.org/schema/mule/stdio/3.1/mule-stdio.xsd
          http://www.mulesoft.org/schema/mule/cxf http://www.mulesoft.org/schema/mule/cxf/3.1/mule-cxf.xsd
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
          http://www.mulesoft.org/schema/mule/jdbc http://www.mulesoft.org/schema/mule/jdbc/3.1/mule-jdbc.xsd
          http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/3.1/mule-xml.xsd  
          ">    
  <spring:bean id="jdbcDataSource" class="org.enhydra.jdbc.standard.StandardDataSource" destroy-method="shutdown">
    <spring:property name="driverName" value="oracle.jdbc.driver.OracleDriver"/>
    <spring:property name="url" value="jdbc:oracle:thin:user/pass@ip:1521:orcl"/>
  </spring:bean>
  <file:connector name="output" outputAppend="true" outputPattern="#[function:datestamp]-#[header:originalFilename]" />
  <file:connector name="input" streaming="false" recursive="true" autoDelete="false"> 

          <service-overrides messageFactory="org.mule.transport.file.FileMuleMessageFactory" /> 

  </file:connector>
        <jdbc:connector name="jdbcConnector" pollingFrequency="10000" dataSource-ref="jdbcDataSource">
           <jdbc:query key="outboundInsertStatement"
              value="INSERT INTO TEST_MESSAGE (message_id, filename, done) VALUES (#[message:id], 
                    #[header:originalFilename], #[string:0])"/>
        </jdbc:connector> 
        <mulexml:namespace-manager includeConfigNamespaces="true">
                <mulexml:namespace prefix="ns1" uri="http://www.iec.ch/TC57/2008/schema/message"/>
                <mulexml:namespace prefix="soapenv" uri="http://schemas.xmlsoap.org/soap/envelope/"/>
                <mulexml:namespace prefix="ns1" uri="http://www.iec.ch/TC57/2008/schema/message"/>
                <mulexml:namespace prefix="fullmodel" uri="iesb.dongfang.com"/>
        </mulexml:namespace-manager> 
    <flow name="fileTestFlow1">

         <file:inbound-endpoint path="D:/data/in" moveToDirectory="D:/data/out" moveToPattern="#[message:id]-#[header:originalFilename]" connector-ref="input"/>
            <component class="com.component.FileNameExtract"/> 

         <message-properties-transformer scope="outbound">

                <add-message-property key="test" value="#[message:id]"/>
         </message-properties-transformer>       
         <jdbc:outbound-endpoint queryKey="outboundInsertStatement"/>         
         <cxf:jaxws-client
               clientClass="com.ws.IESBService"
               port="IESBServiceEndpoint"               
               wsdlLocation="classpath:IESBService.wsdl"
               operation="requestInfo"/>               
         <outbound-endpoint address="http://ip:8888/axis2/services/iESBService/" exchange-pattern="request-response">           
         </outbound-endpoint>         
         <xml-entity-decoder-transformer/>                   
         <logger message=" #[header:test] !" level="INFO"></logger>        
    </flow>   
</mule>

更新: 我尝试了“会话”范围,我认为它有效。新配置:

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns="http://www.mulesoft.org/schema/mule/core"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:file="http://www.mulesoft.org/schema/mule/file"
      xmlns:stdio="http://www.mulesoft.org/schema/mule/stdio"
      xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf"
      xmlns:spring="http://www.springframework.org/schema/beans"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:jdbc="http://www.mulesoft.org/schema/mule/jdbc"
      xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml"
      xsi:schemaLocation="
          http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/3.1/mule-file.xsd
          http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.1/mule.xsd
          http://www.mulesoft.org/schema/mule/stdio http://www.mulesoft.org/schema/mule/stdio/3.1/mule-stdio.xsd
          http://www.mulesoft.org/schema/mule/cxf http://www.mulesoft.org/schema/mule/cxf/3.1/mule-cxf.xsd
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
          http://www.mulesoft.org/schema/mule/jdbc http://www.mulesoft.org/schema/mule/jdbc/3.1/mule-jdbc.xsd
          http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/3.1/mule-xml.xsd  
          ">    
  <spring:bean id="jdbcDataSource" class="org.enhydra.jdbc.standard.StandardDataSource" destroy-method="shutdown">
    <spring:property name="driverName" value="oracle.jdbc.driver.OracleDriver"/>
    <spring:property name="url" value="jdbc:oracle:thin:user/pass@ip:1521:orcl"/>
  </spring:bean>
  <file:connector name="output" outputAppend="true" outputPattern="#[function:datestamp]-#[header:originalFilename]" />
  <file:connector name="input" streaming="false" recursive="true" autoDelete="false"> 

          <service-overrides messageFactory="org.mule.transport.file.FileMuleMessageFactory" /> 

  </file:connector>
        <jdbc:connector name="jdbcConnector" pollingFrequency="10000" dataSource-ref="jdbcDataSource">
           <jdbc:query key="outboundInsertStatement"
              value="INSERT INTO TEST_MESSAGE (message_id, filename, done) VALUES (#[message:id], 
                    #[header:originalFilename], #[string:0])"/>
           <jdbc:query key="outboundUpdateStatement"
              value="update TEST_MESSAGE set done='1' where message_id=#[header:SESSION:test] "/>
        </jdbc:connector> 
        <mulexml:namespace-manager includeConfigNamespaces="true">
                <mulexml:namespace prefix="ns1" uri="http://www.iec.ch/TC57/2008/schema/message"/>
                <mulexml:namespace prefix="soapenv" uri="http://schemas.xmlsoap.org/soap/envelope/"/>
                <mulexml:namespace prefix="ns1" uri="http://www.iec.ch/TC57/2008/schema/message"/>
                <mulexml:namespace prefix="fullmodel" uri="iesb.dongfang.com"/>
        </mulexml:namespace-manager> 
    <flow name="fileTestFlow1">

         <file:inbound-endpoint path="D:/data/in" moveToDirectory="D:/data/out" moveToPattern="#[message:id]-#[header:originalFilename]" connector-ref="input"/>
            <component class="com.component.FileNameExtract"/> 

         <message-properties-transformer scope="outbound">

                <add-message-property key="test" value="#[message:id]"/>
         </message-properties-transformer> 
         <logger message="first #[message:id] " level="INFO"></logger>      
         <jdbc:outbound-endpoint queryKey="outboundInsertStatement"/>         
         <cxf:jaxws-client
               clientClass="com.ws.IESBService"
               port="IESBServiceEndpoint"               
               wsdlLocation="classpath:IESBService.wsdl"
               operation="requestInfo"/>               
         <outbound-endpoint address="http://ip:8888/axis2/services/iESBService/" exchange-pattern="request-response">           
         </outbound-endpoint>         
         <xml-entity-decoder-transformer/>                   
         <jdbc:outbound-endpoint queryKey="outboundUpdateStatement"/>
         <logger message="second #[header:SESSION:test] " level="INFO"></logger>       
    </flow>   
</mule>

当我一个一个复制文件的时候是可以的,但是当我复制超过五个文件到目录时,有些记录无法更新。

 Executing SQL statement: 0 row(s) updated

【问题讨论】:

  • 您是否尝试过在 message-properties-transformer 中使用“会话”范围而不是“出站”,然后使用 #[header:SESSION:test] 稍后检索它?
  • 当我一个一个复制文件时,就可以了。但是当我将五个以上的文件复制到目录时,某些记录无法更新。 “正在执行 SQL 语句:已更新 0 行”

标签: file soap jdbc oracle10g mule


【解决方案1】:

将您的 JDBC 出站端点设置为请求-响应,以确保流程将在单个线程中执行。使用您当前的配置,2 个单独的 JDBC 请求将从流中“分离”并并行执行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-07
    • 1970-01-01
    • 2011-02-10
    • 1970-01-01
    相关资源
    最近更新 更多