2

我需要将文件发送到外部 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
4

1 回答 1

1

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

于 2011-10-01T19:42:30.710 回答