Creating the error handling subflow

Use the following instructions to create the error handling subflow. For more detailed instructions, click the links provided at the end of each step.

  1. Create a new Message Broker project called Error Handler Message Flows.
    For instructions, see Creating a Message Broker project in the WebSphere Message Broker documentation.
  2. Create a new message flow called Error_Handler.
    For instructions, see Creating a message flow in the WebSphere Message Broker documentation.
  3. In the Message Flow editor, add and rename the nodes listed in the following table.
    For instructions, see Adding a message flow node in the WebSphere Message Broker documentation.
    Note: Input and Output in the table are different from MQInput and MQOutput.
    All subflows start with an Input node, and end with an Output node.
    Palette drawers Node type Node name
    Construction Input Start Subflow
    Routing Filter Check Backout Count
    Construction TryCatch TryCatch
    Transformation Compute Copy Message
    Construction Throw Throw To Complete Rollback
    Construction Output Back To Main Flow
    Construction Output STAFF_UPDATE_ERROR
  4. Connect the nodes together as listed in the following table.
    For instructions, see Connecting message flow nodes in the WebSphere Message Broker documentation.
    To check that you have connected the nodes together correctly, see the diagram in About the Error Handler sample.
    Node name Terminal Connect to this node
    Input Out Check Backout Count
    Check Backout Count True TryCatch
    TryCatch Try Back To Main Flow
    Catch Copy Message
    Copy Message Out STAFF_UPDATE_ERROR
    STAFF_UPDATE_ERROR Out Throw To Complete Rollback
  5. Configure the node properties as listed in the following table. Accept the default values for all properties unless an alternative value is listed in the table.
    For instructions, see Configuring a message flow node in the WebSphere Message Broker documentation.
    Node name Page Property Value
    STAFF_UPDATE_ERROR Advanced Trasnasction mode no
    Throw To Complete Rollback Basic Message number 3002
    Basic Message text From Error_Handler message flow.
  6. In the Error Handler Message Flows project, double-click the Error_Handler.esql file to open it in the ESQL editor. Copy and paste the following ESQL code modules to the ESQL file, then save the file. For more information, see Developing ESQL in the WebSphere Message Broker documentation.
    CREATE FILTER MODULE Error_Handler_Filter
       CREATE FUNCTION Main() RETURNS BOOLEAN
       BEGIN
          IF Root.MQMD.BackoutCount='0' THEN
          RETURN TRUE;
          ELSE
             RETURN FALSE;
          END IF;
       END;
    END MODULE;
    
    CREATE DATABASE MODULE Error_Handler_Database
    CREATE FUNCTION Main() RETURNS BOOLEAN
    BEGIN
    
    DECLARE Error INTEGER;
    DECLARE Text CHARACTER;
    DECLARE Place INTEGER;
    DECLARE LastPlace INTEGER;
    DECLARE NodeName CHARACTER;
    DECLARE Label CHARACTER;
    DECLARE FlowName CHARACTER;
    
    -- Set the start point
    DECLARE start REFERENCE TO ExceptionList.*[1];
    WHILE start.Number IS NOT NULL DO 
       SET Error = start.Number;
          IF Error = 3001 THEN
             SET Text = SUBSTRING(start.Insert.Text FROM 1 FOR 250);
             ELSE
             SET Text = SUBSTRING(start.Text FROM 1 FOR 250);
          END IF;
       SET Label = start.Label;
       SET Place = POSITION('.' IN Label); 
       SET LastPlace = Place;
          WHILE Place <> 0 DO
             SET Label=SUBSTRING(Label FROM (Place+1));
             SET Place=POSITION('.' IN Label); 
             SET LastPlace = LastPlace + Place; 
          END WHILE;
       SET Label=start.Label;
       SET FlowName=SUBSTRING(Label FROM 1 FOR (LastPlace-1));
       SET NodeName=SUBSTRING(Label FROM (LastPlace+1));
    -- Move start to the last child of the field to which it currently points
              MOVE start LASTCHILD;
    END WHILE;
    INSERT INTO Database.ERRORS(MSGID,TEXT,ERRORNUM, ERRORDATE,MSGDATA,FLOWNAME,NODENAME)
    VALUES(CAST(Root.MQMD.MsgId AS BLOB),Text,Error,CURRENT_TIMESTAMP,BITSTREAM(Root),
    FlowName,NodeName);
          RETURN TRUE;
       END;   
    END MODULE
    
    CREATE COMPUTE MODULE Error_Handler_Compute
    CREATE FUNCTION Main() RETURNS BOOLEAN
    BEGIN
    CALL CopyMessageHeaders();
    CALL CopyEntireMessage();
    RETURN TRUE;
    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;
    
    CREATE PROCEDURE CopyEntireMessage() BEGIN
    SET OutputRoot = InputRoot;
    END;
    END MODULE;
    
  7. Save the message flow.
You can now create the main message flow, which incorporates the error handling subflow, see Creating the main message flow.

Back to Building the Error Handler sample