写入文件后如何在 mule 流中使用 sftp?
How to use sftp in the mule flow after writing a file?
我有一个编排流,它调用一个子流来写入文件,然后下一个流(通过流引用)将其发送到 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"/>
然后我调用一个流程(通过 ref)启动 sftp 进程。
<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>
问题是
在写入文件时,流程在文件出站端点后执行记录器并表示文件已写入,一段时间后文件连接器吐出"Write file to ..."。我如何让记录器等待文件完成写入??
上面流 sftp 中的文件入站端点立即执行,文件尚未准备好。所以它首先抛出一个异常,说它期待一个 InputStream 或 byte[] 或 String 但得到一个 ArrayList(这是来自编排流的原始有效负载)。打印此异常后,文件终于准备就绪,入站文件连接器开始读取它并 sftps 正常。这似乎与上述问题有关,我需要以某种方式让流程的其余部分等待文件写入完成。
注意:我必须将 sftp 流创建为流而不是子流,因为它需要是源。我认为如果我不将其创建为流并且不将文件连接器作为源,它将成为出站连接器。
感谢任何帮助。
1) 将流的 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/
所以我终于弄明白了,不知何故这两个问题都在一个博客 post 这里得到了回答
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 请求器模块。
我有一个编排流,它调用一个子流来写入文件,然后下一个流(通过流引用)将其发送到 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"/>
然后我调用一个流程(通过 ref)启动 sftp 进程。
<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>
问题是
在写入文件时,流程在文件出站端点后执行记录器并表示文件已写入,一段时间后文件连接器吐出"Write file to ..."。我如何让记录器等待文件完成写入??
上面流 sftp 中的文件入站端点立即执行,文件尚未准备好。所以它首先抛出一个异常,说它期待一个 InputStream 或 byte[] 或 String 但得到一个 ArrayList(这是来自编排流的原始有效负载)。打印此异常后,文件终于准备就绪,入站文件连接器开始读取它并 sftps 正常。这似乎与上述问题有关,我需要以某种方式让流程的其余部分等待文件写入完成。
注意:我必须将 sftp 流创建为流而不是子流,因为它需要是源。我认为如果我不将其创建为流并且不将文件连接器作为源,它将成为出站连接器。
感谢任何帮助。
1) 将流的 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/
所以我终于弄明白了,不知何故这两个问题都在一个博客 post 这里得到了回答 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 请求器模块。