You can use the
DECLARE statement to define three types of variable:
- External
- External variables (defined with the EXTERNAL keyword) are also known
as user-defined properties (UDPs): see User-defined properties in ESQL.
They exist for the entire lifetime of a message flow and are visible to all
messages passing through the flow. Their initial values (optionally set by
the DECLARE statement) can be modified, at design time, by the Message Flow
editor, or, at deployment time, by the BAR editor. Their values cannot be
modified by ESQL.
- Normal
- "Normal" variables have a lifetime of just one message passing through
a node. They are visible to that message only. To define a "normal" variable,
omit both the EXTERNAL and SHARED keywords.
- Shared
- Shared variables can be used to implement an in-memory cache in the message
flow, see Optimizing message flow response times. Shared variables have a long
lifetime and are visible to multiple messages passing through a flow, see Long-lived variables. They exist for the lifetime of
the execution group process, the lifetime of the flow or node, or the lifetime
of the node’s SQL that declares the variable (whichever is the shortest).
They are initialized when the first message passes through the flow or node
after each broker start up.
See also the ATOMIC option
of the BEGIN ... END statement. The BEGIN ATOMIC construct is useful
when a number of changes need to be made to a shared variable and it is important
to prevent other instances seeing the intermediate states of the data.