"mule4 SFTP write connector writing file with timestamp , move connector unable to fetch filename from different flow"

"mule4 SFTP write connector writing file with timestamp , move connector unable to fetch filename from different flow"

为了在 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'

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

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

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

    <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