flow子流量未触发

时间:2018-06-29 17:45:35

标签: mule mule-component mule-el mule-esb

我正在Poll内部使用Groovy检查文件在给定位置的存在。 有文件时,我的流程运行正常。但是,如果我删除该文件,则不会触发流程。下面是我的代码

<flow name="monitor-dst-file-flow">
    <poll doc:name="Poll">
        <schedulers:cron-scheduler expression="0 0 23 ? * TUE-SAT"/>
        <scripting:transformer doc:name="Groovy">
            <scripting:script engine="Groovy"><![CDATA[def endpointBuilder = muleContext.endpointFactory.getEndpointBuilder( 
                "sftp://${user}:${pwForGroovy}@${host}:${port}${inputpath}/?connector=SFTP")                    
                endpointBuilder.addMessageProcessor(new org.mule.routing.MessageFilter(new org.mule.transport.file.filters.FilenameWildcardFilter('test.txt'))) 

def inboundEndpoint = endpointBuilder.buildInboundEndpoint()                     inboundEndpoint.request(30000L)]]>

        </scripting:transformer>
    </poll>
    <choice doc:name="Choice">
        <when expression="#[message.inboundProperties.originalFilename ==&quot;test.txt&quot;]">
            <logger level="INFO" doc:name="Logger" message="File Exists..."/>
        </when>
        <otherwise>

            <logger message="FILE EXISTS" level="ERROR" doc:name="Logger"/>

            <flow-ref name="email-notification-sub-flow" doc:name="Flow Reference"/>

        </otherwise>
    </choice>
</flow>

在这里,如果没有test.txt文件,则无法调试Choice组件。

它说-Polling of monitor-dst-file-flow returned null, the flow will not be invoked. 我无法确定运行流程的确切解决方案。如果给定文件不存在,我必须处理这种情况。

1 个答案:

答案 0 :(得分:1)

您需要从轮询者的目标中返回null之外的内容,以调用该流。我建议在子流中执行此操作:

<flow name="monitor-dst-file-flow">
  <poll doc:name="Poll">
    <schedulers:cron-scheduler expression="0 0 23 ? * TUE-SAT"/>
    <flow-ref name="pollerProcessor" doc:name="pollerProcessor"/>
  </poll>
  <choice doc:name="Choice">
    <when expression="#[payload == 'file not found']">
      <logger level="INFO" doc:name="Logger" message="File Exists..."/>
    </when>
    <otherwise>
      <logger message="FILE EXISTS" level="ERROR" doc:name="Logger"/>
      <flow-ref name="email-notification-sub-flow" doc:name="Flow Reference"/>
    </otherwise>
  </choice>
</flow>
<sub-flow name="pollerProcessor">
  <scripting:transformer doc:name="Groovy">
    <scripting:script engine="Groovy"><![CDATA[def endpointBuilder = muleContext.endpointFactory.getEndpointBuilder( 
      "sftp://${user}:${pwForGroovy}@${host}:${port}${inputpath}/?connector=SFTP")                    
      endpointBuilder.addMessageProcessor(new org.mule.routing.MessageFilter(new org.mule.transport.file.filters.FilenameWildcardFilter('test.txt'))) 
      def inboundEndpoint = endpointBuilder.buildInboundEndpoint() inboundEndpoint.request(30000L)]]>
    </scripting:script>
  </scripting:transformer>
  <set-payload value="#[payload == null ? 'file not found' : payload]" doc:name="Set Payload"/>
</sub-flow>