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. In the Message Brokers Toolkit, switch to the Broker Application Development perspective.
  2. Create a new message flow project called Error Handler Message Flows.
    For instructions, see Creating a message flow project.
  3. Create a new message flow called Error_Handler.
    For instructions, see Creating a message flow.
  4. In the Message Flow editor, add and rename the nodes listed in the following table.
    For instructions, see Adding a node. Note that 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
    WebSphere MQ Input Start Subflow
    Routing Filter Check Backout Count
    Construction TryCatch TryCatch
    Database Database Update Error Database
    Construction Throw Throw To Complete Rollback
    WebSphere MQ Output Back To Main Flow
  5. Connect the nodes together as listed in the following table.
    For instructions, see Connecting nodes.
    To check that you have connected the nodes together correctly, see the figure 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 Update Error Database
    Update Error Database Out Throw To Complete Rollback
  6. 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 node.
    Node name Page Property Value
    Update Error Database Basic Data source ERRORDB
    Basic Transaction Commit
    Throw To Complete Rollback Basic Message number 3002
    Basic Message text From Error_Handler message flow. See ERRORDB for details.
  7. 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.
    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
  8. Save the message flow.
You can now create the main message flow, which incorporates this subflow: Creating the main message flow.

Main Page icon   Back to Building the Error Handler sample.