106 Using IBM WebSphere Message Broker as an ESB with WebSphere Process Server
Example 5-5 shows the ESQL code that implements the node. It performs the
following actions:
1. The message is split into individual orders.
2. Each order is parsed to determine the supplier ID that is associated with the
order. The destination queue to which this order is delivered must match the
supplier’s queue.
3. To determine the destination queue for the order, a database table is
searched for the destination queue that is associated with the supplier ID.
4. If the destination queue is returned from the database successfully, the
destination queue of the message is set to that queue.
5. If database errors are reported by the select statement, the message is
routed to a holding queue for messages for which no destination queue could
be determined due to issues in communicating with the database.
6. If no database error occurred, but no destination queue is returned, the
message is routed to a different holding queue.
7. For each message contained in the multipart message, a single message is
sent to the out terminal of the compute node. Each of these single messages
will have a destination queue set in LocalEnvironment.
Example 5-5 ESQL code for RouteMsgToDestinationQ
CREATE COMPUTE MODULE RouteMsgToDestinationQ
CREATE FUNCTION Main() RETURNS BOOLEAN
BEGIN
/* In this module, we loop through all the instances in the incoming message.
We query the database for an onward routing queue for each supplier id.
If we have a match, we route that instance of the message to the relevant
queue. If we do not have a match or if we encounter problems, we craft an
appropriate message and write that message to a queue.
*/
DECLARE forRef REFERENCE TO InputRoot.MRM;--used to loop through input msg
DECLARE ileRef REFERENCE TO InputLocalEnvironment;
DECLARE oleRef REFERENCE TO OutputLocalEnvironment;
DECLARE suppID CHAR; -- used to store the supplier id
MOVE forRef FIRSTCHILD NAME 'Orders'; -- Move our loop reference to the start
-- of the folder holding all instances
-- of Order elements.
-- Perform the following actions for each instance of
-- 'Order' within the incoming message
FOR forRef AS forRef.Order[] DO
(1)
CALL CopyMessageHeaders();