【问题标题】:Reading files from SFTP with file name filter on poll basis in mule在骡子的轮询基础上,使用文件名过滤器从 SFTP 读取文件
【发布时间】:2017-11-17 18:16:40
【问题描述】:

我正在使用带有文件名过滤器的 groovy 脚本,使用以下代码从 SFTP 位置读取文件以轮询为基础

 <poll doc:name="Poll">
            <schedulers:cron-scheduler expression="${payment.schedule}"/>
            <scripting:transformer doc:name="Groovy">
                <scripting:script engine="Groovy">
                    <scripting:text><![CDATA[    
            def endpointBuilder = muleContext.endpointFactory.getEndpointBuilder( 
                    "sftp://${sftp.user}:${sftp.password}@${sftp.host}:${sftp.port}/${sftp.root.path}") 
                    endpointBuilder.addMessageProcessor(new org.mule.routing.MessageFilter(new org.mule.transport.file.filters.FilenameWildcardFilter('payment_*'))) 
                    def inboundEndpoint = endpointBuilder.buildInboundEndpoint() 
                    inboundEndpoint.request(3000L) ;
                    ]]></scripting:text>
                </scripting:script>
            </scripting:transformer>
</poll> 

我在这里面临的问题是,它在每个轮询时间表上只读取一个文件。 但是,我的期望是,它应该在每个轮询计划中从 SFTP 位置读取满足过滤条件的所有文件。

我怎样才能做到这一点? 谢谢。

【问题讨论】:

标签: groovy mule sftp polling


【解决方案1】:

您可能希望将 SFTP 入站端点与 file:filename-wildcard-filter 一起使用,而不是依赖于包含在轮询中的 Groovy 脚本。如:

<sftp:inbound-endpoint host="${sftp.host}" port="${sftp.port}" path="/home/test/sftp-files" user="${sftp.user}" password="${sftp.password}"> 
    <file:filename-wildcard-filter pattern="payment_*"/> 
</sftp:inbound-endpoint>

请参阅related example in SFTP documentation

【讨论】:

  • 它会在一个轮询计划中开始处理所有文件吗?
  • 是的,它会根据您的模式一次轮询所有文件。自己试试吧;)
  • 谢谢皮埃尔。我不知道 SFTP 连接器中的文件名通配符过滤器。
  • 太好了,底层类可能与您在 Groovy 脚本中定义的类相同,但它是内置在 XML 中并正式记录在案的。如果这有助于您解决问题,请随时投票和/或接受 ;)
猜你喜欢
  • 2018-03-05
  • 1970-01-01
  • 1970-01-01
  • 2022-01-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多