【问题标题】:How to use sftp in the mule flow after writing a file?写入文件后如何在 mule 流中使用 sftp?
【发布时间】:2015-07-22 14:55:56
【问题描述】:

我有一个编排流程,它调用一个子流程来写入文件,然后下一个流程(通过流程引用)对它进行 sftp。

写子流

 <file:outbound-endpoint path="${outputDir}" outputPattern="${fileName}" responseTimeout="10000" doc:name="Write file"/>

 <logger message="File ${fileName}  written to ${outputDir}" level="INFO" doc:name="End"/>

然后我调用一个启动 sftp 进程的流(通过 ref)。

<flow name="sftp">
    <file:inbound-endpoint path="${outputDir}" connector-ref="File" responseTimeout="10000" doc:name="File">
        <file:filename-regex-filter pattern="${fileName}" caseSensitive="true"/>
    </file:inbound-endpoint>
    <sftp:outbound-endpoint exchange-pattern="one-way" connector-ref="SFTP"  responseTimeout="10000" ref="endpoint" doc:name="SFTP"  />
</flow>

问题是

  1. 在写入文件时,流程会在文件出站端点之后执行记录器并说文件已写入,然后文件连接器会吐出“将文件写入...”。我如何让记录器等待文件完成写入??

  2. 上述流 sftp 中的文件入站端点立即执行,文件尚未准备好。所以它首先抛出一个异常,说它期望一个 InputStream 或 byte[] 或 String 但得到一个 ArrayList(这是来自编排流的原始有效负载)。打印此异常后,最终文件准备就绪,入站文件连接器开始读取它并正常 sftps。这似乎与上述问题有关,我需要以某种方式使流程的其余部分等待文件写入完成。

注意:我必须将 sftp 流创建为流而不是子流,因为它需要是源。我想如果我不创建一个流并且没有文件连接器作为源,它将成为出站连接器。

任何帮助表示赞赏。

【问题讨论】:

    标签: java mule sftp


    【解决方案1】:

    所以我终于想通了,不知何故,这两个问题都在这里的一篇博文中得到了回答 http://www.sixtree.com.au/articles/2015/advanced-file-handling-in-mule/

    #1 的关键是

     <file:connector name="synchronous-file-connector" doc:name="File">
         <dispatcher-threading-profile doThreading="false"/>
    </file:connector>
    

    对于 Ryan 上面提到的 #2,使用 mule requester 模块。

    【讨论】:

    • 请接受 Ryan 或您的回答,将此问题标记为已关闭。谢谢!
    【解决方案2】:

    1) 将 Flow 的 procesingStrategy 设置为 synchronous:

    <flow name="testFlow" processingStrategy="synchronous">
            <poll frequency="10000">
                <set-payload value="some test text" />
            </poll>
    
            <file:outbound-endpoint path="/Users/ryancarter/Downloads"
                outputPattern="test.txt" />
    
            <logger level="ERROR" message="After file..." />
    </flow>
    

    2) 不确定我是否完全理解,但您不能通过 flow-ref 调用入站端点,因此入站端点将被忽略,入站端点将自行运行,而不管调用流程如何。如果您想在流程中读取文件,请使用 mule-requestor 模块:http://blogs.mulesoft.com/introducing-the-mule-requester-module/

    【讨论】:

    • 文件写入是在子流程中完成的。那么在这种情况下我应该将其更改为流程吗?如果我更改为流,流的来源是什么?我真的不需要将任何内容发送到此子流,因此在将控制权传递给此流之前,有效负载被显式设置为 null。
    • Mulerequestor 帮助和 1. 请参阅下面的答案。以上可能有效,但对于我的情况它没有,因为这是在我的子流程中而不是在流程中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多