gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 05:42:02 27 4
gpt4 key购买 nike

为了在 SFTP 写入连接器中获取文件名,我已将文件名存储在变量中并写入文件(暂存),然后将其写入目录。从不同的流中,我需要将相同的文件移动到输出位置,两个流不是相互链接的。

Mule4 中没有 Session 变量来实现这种情况。
谁能告诉我如何在一个流中存储文件名(带时间戳)等变量并从不同的流中读取它。

EX: 文件名模式 "test"++ "_"++ now() as Date {格式:"yyyyMMdd"}++ "_"++ (now() as String {格式:"HH :mm:ss"})++ '.txt'

最佳答案

session 变量没有帮助,因为它们需要在事件上序列化,并且由于流程不是相互链接的,所以这是行不通的。

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

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

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

并检索另一个流():

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

或者这将检索所有 key :

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

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

或者您可以检索特定 key ,例如:

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

这里是一些示例配置:

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

关于java - "mule4 SFTP write connector writing file with timestamp , move connector unable to fetch filename from different flow",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55467988/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com