I have a flow with lots of nodes and calls to my DBs, and I need to use at the end of the flow a field that was pulled from a DB at the beginning of the flow.
So far I have been passing the value all along the message flow which is a bit inefficient and complex (at the end of the flow my msg is clogged with many temporary information).
I have read that the flow context might be the solution, but one thing is unclear: is the flow object unique for all messages that enter my flow or is it unique per message?
eg message 1 comes, I store and use flow.siteId.
message 2 comes, I will also store and use flow.siteId, but is the previous flow.siteID still there?
I will end up with many messages coming simultaneously, so if flow.siteID is a single variable used by all messages, it will be an issue.
ok thanks, so I should not use it for temp values along my flow.
Is that the best practice, to just store some msg.tempData all along the flow to reuse them when I need it later in the flow ?
Your flow can be triggered multiple times, meaning multiple independent message objects. So everything you need along a single flow execution (temp values) should be carried by the message object.
The flow context should be used if you need to share data between independent flow executions, e.g. for aggregation, counting, ...
That is what I would do, though I would give it a meaningful name. All information in a message is temporary. You said at the start that this is inefficient and complex. There is little impact on efficiency as usually a message is passed along the flow by reference, nothing is actually moved about, it does not keep creating recreating messages. The message stays where it is and a pointer to it is passed along. It should not be complex if you structure msg.tempData in a meaningful way.
An alternative which may be appropriate is to send the extra data off on another wire bypassing all the nodes between and use a Join node in Key/Value pairs mode or Merge mode to join it back in when you need it.