“ mule4 SFTP写连接器带有时间戳,移动连接器无法从其他流中获取文件名”

时间:2019-04-02 06:09:59

标签: java mule mule4

要在SFTP写入连接器中获取文件名,我将文件名存储在变量中并在将文件写入目录后写入文件(分段)。从不同的流中,我需要将同一文件移动到输出位置,两个流没有相互链接。

we dont have Session variable in Mule4 to achieve this scenario. Could anyone let me know how to store variable like filename(with timestamp) in one flow and read it from different flow.

EX: filename pattern "test" ++ "_" ++ now() as Date {format: "yyyyMMdd"} ++ "_" ++ (now() as String {format: "HH:mm:ss"}) ++ '.txt'

1 个答案:

答案 0 :(得分:1)

会话变量无济于事,因为它们需要在事件上进行序列化,并且由于流没有相互关联,所以这行不通。

要在不同流之间共享状态,可以使用对象存储。这是一个基于键值的存储,可以在内存中或持久存储。

它将允许您将文件名存储在一个流中:

    <os:store key="#[vars.filename]" objectStore="${objectStore}" />

并获取另一个流():

    <os:retrieve-all objectStore="${objectStore}"/>

否则将检索所有密钥:

    <os:retrieve-all-keys objectStore="${objectStore}"/>

然后使用foreach迭代所有键并执行您的逻辑。

或者您可以检索特定的密钥,例如:         

ObjectStore连接器上还有许多其他可用的操作。这是官方文档: https://docs.mulesoft.com/object-store/

这是一些示例配置:

https://github.com/mulesoft/mule-objectstore-connector/tree/master/src/test/resources