The Environment tree has its own correlation name, Environment, and you must use this in all ESQL statements that refer to or set the content of this tree.
The Environment tree is always created when the logical tree is created for an input message. However the message flow neither populates it nor uses its contents. You can use this tree for your own purposes, for example to pass information from one node to another. You can use the whole tree as a scratchpad or working area.
The advantage of creating your own data in Environment is that this data is propagated as part of the logical tree to subsequent nodes in the message flow. If you create a new output message in a Compute node, the Environment tree is also copied from the input message to the new output message. (This is in contrast to the LocalEnvironment tree, which is only included in the output message if you explicitly request that it is).
Only one Environment tree is present for the duration of the message flow. Any data updates or additions that you make in one node are retained and all nodes in the message flow have access to the latest copy of this tree. Even if the message flows back through the message flow (for example, if an exception is thrown, or if the message is processed through the second terminal of the FlowOrder node), the latest state is retained.
This is in contrast to the LocalEnvironment tree, which reverts to its previous state if the message flows back through the message flow.
SET Environment.Variables = ROW('granary' AS bread, 'reisling' AS wine, 'stilton' AS cheese); SET Environment.Variables.Colors[] = LIST{'yellow', 'green', 'blue', 'red', 'black'}; SET Environment.Variables.Country[] = LIST{ROW('UK' AS name, 'pound' AS currency), ROW('USA' AS name, 'dollar' AS currency)};
This information is now available to all nodes to which a message is propagated, regardless of their relative position in the message flow.
For another example of how you can use Environment to store information used by other nodes in the message flow, refer to the Reservation message flow in the Airline Reservations sample. The Compute node in this message flow writes information to the subtree Environment.Variables that it has extracted from a database according to the value of a field in the input message. You can view samples only when you use the information center that is integrated with the Message Brokers Toolkit.