Chapter 5. Scenario: Message splitting and routing 107
SET suppID = forRef.Supplier.SupplierID;
(2)
SET ileRef.Variables.destQ[] = (SELECT R.DESTINATION_QUEUE
(3)
FROM Database.BKR_FLOW_DATA.ROUTING AS R
WHERE R.SUPPLIER_ID = suppID);
CASE -- Let's see if we have any errors/missing values after our attempt
-- to retrieve routing details from the database
WHEN SQLCODE <> 0 THEN
(5)
-- There is a database access problem.
--Let's report it on the relevant queue
SET oleRef.Destination.MQDestinationList.DestinationData[1].queueName
= 'HOLDINGQ_MSGS_WITH_DB_ACCESS_ISSUES';
CREATE LASTCHILD OF OutputRoot DOMAIN('XML');
SET OutputRoot.XML.Message.Summary =
'Database problem encountered when attempting to '||
'retrieve routing data for an instance of a '||
'ProcessOrdersRequest message';
SET OutputRoot.XML.Message.Details.Detail[1] =
'SQLSTATE is: ' || CAST(SQLSTATE AS CHAR);
SET OutputRoot.XML.Message.Details.Detail[2] =
'SQLCODE is: ' || CAST(SQLCODE AS CHAR);
SET OutputRoot.XML.Message.Details.Detail[3] =
'SQLERRORTEXT is: ' || CAST(SQLERRORTEXT AS CHAR);
SET OutputRoot.XML.Message.Details.Detail[4] =
'SQLNATIVEERROR is: ' || CAST(SQLNATIVEERROR AS CHAR);
WHEN NOT EXISTS(ileRef.Variables.destQ[]) THEN
(6)
-- No routing entry found for supplier. Send a message
-- to the 'invalid destination' queue
SET oleRef.Destination.MQDestinationList.DestinationData[1].queueName =
'HOLDINGQ_MSGS_WITH_INVALID_DESTINATIONS';
CREATE LASTCHILD OF OutputRoot DOMAIN('XML');
SET OutputRoot.XML.Message.Summary =
'No routing entry exists for the following instance of a
ProcessOrdersRequest message';
ELSE
(4)
-- All ok. Let's setup the destination queue using the routing
-- details retrieved from the database
SET oleRef.Destination.MQDestinationList.DestinationData[1].queueName =
TRIM(ileRef.Variables.destQ[1].DESTINATION_QUEUE);
END CASE;
108 Using IBM WebSphere Message Broker as an ESB with WebSphere Process Server
--Build the rest of the message to propagate
SET OutputRoot.MRM.BatchNumber = InputBody.BatchNumber;
SET OutputRoot.MRM.Orders.Order = forRef;
PROPAGATE;
END FOR;
RETURN FALSE;
END;
CREATE PROCEDURE CopyMessageHeaders() BEGIN
DECLARE I INTEGER 1;
DECLARE J INTEGER;
SET J = CARDINALITY(InputRoot.*[]);
WHILE I < J DO
SET OutputRoot.*[I] = InputRoot.*[I];
SET I = I + 1;
END WHILE;
END;
END MODULE;
TryCatch node
The TryCatch node routes the message to the MQOutput node via its Try
terminal. Should an exception be generated in the MQOutput node when it
attempts to put the message into the destination queue, the message is rolled
back to the TryCatch node. The TryCatch node then routes the message down its
Catch terminal to the AddExceptionListToMsg Compute node.
AddExceptionListToMsg Compute node
When an exception is generated in a flow, an exception list is generated and
added to the message tree. The AddExceptionListToMsg Compute node adds
that exception list to the body of the message before the message is written to
the TryCatch queue.
Chapter 5. Scenario: Message splitting and routing 109
The Basic properties (Figure 5-25) define the location of the ESQL module that is
used to implement the logic of this node.
Figure 5-25 AddExceptionListToMsg node - Basic properties
Example 5-6 shows the ESQL that is used to implement this node.
Example 5-6 ESQL code for AddExceptionListToMsg
CREATE COMPUTE MODULE AddExceptionListToMsg
CREATE FUNCTION Main() RETURNS BOOLEAN
BEGIN
/* In this module, we simply create a message containing the message
we tried to write to the destination queue and the exception generated
when we attempted to write that message.
*/
DECLARE qName CHAR;
CALL CopyMessageHeaders();
SET qName =
InputLocalEnvironment.Destination.MQDestinationList.DestinationData[1].queueName;
CREATE LASTCHILD OF OutputRoot DOMAIN('XML');
SET OutputRoot.XML.Message.Summary =
'There was a problem writing a message to the queue: '
|| qName || ' The exception generated was:';
SET OutputRoot.XML.Message.ExceptionList =
InputExceptionList.*[1].RecoverableException[<];
SET OutputRoot.XML.Message.OriginalMessage = InputRoot;
RETURN TRUE;
END;
110 Using IBM WebSphere Message Broker as an ESB with WebSphere Process Server
CREATE PROCEDURE CopyMessageHeaders() BEGIN
DECLARE I INTEGER 1;
DECLARE J INTEGER;
SET J = CARDINALITY(InputRoot.*[]);
WHILE I < J DO
SET OutputRoot.*[I] = InputRoot.*[I];
SET I = I + 1;
END WHILE;
END;
END MODULE;
MQOutput node
The MQOutput node delivers the message to the destination queue defined in
the LocalEnvironment element of the message tree:
LocalEnvironment.Destination.MQDestinationList.DestinationData[1].
queueName
The destination was previously defined in the LocalEnvironment element by the
RouteMsgToDestinationQ Compute node.
In the Advanced properties of the MQOutput node, you set Destination mode to
Destination list
, so that the MQOutput node knows to search the
LocalEnvironment structure of the message for the destination queue (Figure 5-26).
Figure 5-26 MQOutput node - Advanced properties
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.135.4