You can include subflows in your message flows in exactly
the same way as you include built-in
or user-defined nodes.
You can also connect them to
other nodes in the same way. Because you can define a subflow once, and use
it in more than one message flow (and even in more than one message flow project),
a subflow can provide benefits:
- Reuse and reduced development time.
- A consistent way of achieving a particular function, and increased maintainability
of your message flows (consider a subflow as analogous to a programming macro,
or to inline code that is written once but used in many places).
- Flexibility. If you promote some or all of the properties of the nodes
in the subflow, you can tailor a subflow to a specific context (for example,
by updating the output queue or data source information).
However, you must remember that a subflow is not a single node, and
its inclusion increases the number of nodes in the message flow, which might
affect its performance.
Consider these examples of subflow use:
- You can define a subflow that provides a common sequence
of actions that applies to several message flows if an error is encountered.
For example, you might have a common error routine that writes the message
to a database through the Warehouse node, and puts it to a queue for processing
by an error recovery routine. The use of this routine in multiple message
flows, or in several places within one message flow, provides an efficient
and consistent use of resources and avoids reinventing such routines every
time an error is encountered.
- You might have a common calculation that you want to perform
on messages that pass through several different message flows. For example,
you might access currency exchange rates from a database and apply these to
calculate prices in several different currencies. You can include the currency
calculator subflow in each of the message flows in which it is appropriate.
The use of subflows is illustrated in the following sample:
The use of subflows is demonstrated in the Error Handler sample and the Coordinated Request Reply sample.
The Error Handler sample uses a subflow to trap information about errors and
store the information in a database. The Coordinated Request Reply sample
uses a subflow to encapsulate the storage of the ReplyToQ and ReplyToQMgr
values in a WebSphere MQ message so that the processing logic can be easily
reused in other message flows and to allow alternative implementations to
be substituted.