Chapter 7. Implementing highly available brokers 257
Figure 7-50 Trace node properties
Properties of the Filter node
The Filter node routes a message according to the message content. You define
the route by coding a filter expression in ESQL. The filter expression for our
scenario checks the message field Resource, which can be mem, cpu, or disk.
Right-click the Filter node and select Open ESQL. A new editor opens for an
ESQL file. The ESQL functionality used in our scenario is shown in Example 7-8.
In the ESQL function, if the ResouceType field in the message contains the string
cpu, then the message will be routed to TRUE terminal. If the ResourceType in
the message contains the string mem, then the message will be routed to FALSE
terminal. Otherwise, the message will be routed to UNKNOWN terminal.
Example 7-8 ESQL for Filter node
CREATE FILTER MODULE ResourceUsageMsgflow_Filter
CREATE FUNCTION Main() RETURNS BOOLEAN
BEGIN
IF Body.ResourceType like 'cpu' THEN
RETURN TRUE;
END IF ;
IF Body.ResourceType like 'mem' THEN
RETURN FALSE;
END IF;
258 Messaging Solutions in a Linux Environment
RETURN UNKNOWN;
END;
END MODULE;
Properties of MQOutput nodes
The MQOutput node is used to write a message to an MQ queue. The message
flow uses two MQOutput nodes. One is used to write a message when the Filter
node fails. The other one is used to write a message when the Filter node returns
Unknown as the result of the filter. Set the properties of the two MQOutput nodes
as illustrated in Figure 7-51 and Figure 7-52 on page 259.
Figure 7-51 Fail MQOutput Node property
Note: The Filter node is clearly best-suited for a traditional IF-THEN-ELSE
programming construct. For the equivalent of a CASE programming construct,
use the RouteToLabel and Label nodes. In the ESQL for a Compute node, you
can populate an element called DestinationList. This list should contain the
appropriate label (or case). Label nodes are added to the message flow for
each possible value of the label. The RouteToLabel node typically follows the
Compute node and jumps to the appropriate Label node that corresponds with
the value in the element DestinationList.
Chapter 7. Implementing highly available brokers 259
Figure 7-52 Unknown MQOutput Node property
Properties of DataInsert nodes
A DataInsert node is used to insert records in a database table using parts of a
message that hits the node at its in terminal. The database should be defined as
an ODBC data source.
The DataInsert node is a specialized version of the Database node and can be
used for all kinds of database interaction. The Database node itself can be
considered a specialized version of the Compute node. In the end, everything
that you can do with a DataInsert node or with a Database node can be
performed as well using a Compute node. The only difference is that you need to
write ESQL in a Compute node, while you have graphical tools to help you
customize the Database and DataInsert nodes.
1. The first step is to set the database name in the properties of the DataInsert
node. This name is actually the name of the ODBC data source. Set the
properties of two DataInsert nodes as illustrated in Figure 7-53 on page 260
and Figure 7-54 on page 260.
260 Messaging Solutions in a Linux Environment
Figure 7-53 DatabaseInsert node properties
Figure 7-54 DatabaseInsert node properties
2. The next step is to define the mapping between the elements of the incoming
message and the columns of the database table. In this scenario, the
mapping is straightforward. We map the elements of the message to the
columns in the database. The mappings are shown in Table 7-5 on page 261.
Chapter 7. Implementing highly available brokers 261
Table 7-5 Mapping between message elements and table columns
To implement this mapping in the Message Brokers Toolkit, perform the
following steps:
a. Right-click the DataInsert node and select Open Mappings. The mapping
editor will open as illustrated in Figure 7-55.
Figure 7-55 Mapping editor
b. In the mapping editor, right-click in the top area labeled Source and select
Add Message Mapping Input. In the Add Message window, select the
ResourceUsage message definition and click Finish as illustrated in
Figure 7-56 on page 262.
Message element Column in table
Time TIME
ResourceType RESOURCE
Usage USAGE
Qmgr QMGR

Get Messaging Solutions in a Linux Environment now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.