简体   繁体   中英

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

To fetch Filename in SFTP write connector, i have stored filename in variable and writing file(staging), after it written in directory. from different flow i need to move same file to output location both flows are not interlinked.

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'

Session vars wouldn't help as they need to be serialized on an event and as the flows are not interlinked, this wouldn't work.

To share state between different flows you can use the Object Store. This is a Key-Value based store that can be in-memory or persistent.

It will allow you to store your filename in one flow:

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

And retrieve it another flow ():

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

Or this will retrieve all keys:

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

And then use a foreach to iterate all keys and perform your logic.

Or you can retrieve a specific key for example:

There's lot of other operations available on the ObjectStore connector. Here are the official docs: https://docs.mulesoft.com/object-store/

And here are some example configs:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM