Adding sequence numbers to messages

You can add sequence numbers to messages entering a message flow by using the Sequence node.

Before you begin

Read the concept topic about Message sequencing.

About this task

The Sequence node allocates a monotonically increasing sequence number for each input message that arrives at the node. As each message arrives at the Sequence node, the sequence number is incremented and stored with the message in the location specified by the Path to store sequence number property. The allocation of sequence numbers continues until the sequence ends, as specified by the End of sequence definition property.

You can divide input messages into independent sequence groups, based on an identifier defined in the message. Each group has a separate group identifier, and the sequence of messages within each group is managed independently.

The Sequence node allocates a sequence number to each message in the sequence group, and the next sequence number in the group is not allocated until the current message in the group has finished processing (either by being committed or rolled back). This ensures that sequencing is maintained for the group when there are multiple threads in the message flow.

If you need to save the message with the newly assigned sequence number (for example, if you need to save the message to IBM MQ for processing by another flow), and if there is no convenient place in the message to save the sequence number, you can add an MQRFH2 header to the message before the Sequence node, and set the sequence number in a field in the usr folder.

Multiple sequence groups can be managed independently, in parallel, and sequence group state is preserved when the integration node is restarted.

The following steps show how to create a message flow that adds a sequence number to each message in a sequence group.

Procedure

  1. Create a message flow containing an MQInput node, a Sequence node, and an MQOutput node.
  2. Connect the Out terminal of the MQInput node to the In terminal of the Sequence node.
  3. Connect the Out terminal of the Sequence node to the In terminal of the MQOutput node.
    Message flow consisting of MQInput, Sequence, and MQOutput nodes.
  4. On the MQInput node, specify the source of input messages for the node by setting the Queue name property (on the Basic tab) to the name of an IBM MQ queue, from which the MQInput node retrieves messages. For example: SEQ.TASK1.IN1.
  5. Set the following properties of the Sequence node:
    1. On the Basic tab, set the following properties:
      • Set the Path to store sequence number property to the location in the message where the sequence number is to be set. For example, $OutputBody/doc/seq. The sequence number is also set in the local environment, with the LocalEnvironment.Sequence.Number variable.
      • Set the Path to sequence group identifier property to the location of the sequence group identifier in the message. For example, $InputBody/doc/grp. The sequence group identifier is also copied to the local environment, with the LocalEnvironment.Sequence.Group variable.
      • Set the Start of sequence definition property to Literal with the required starting value; for example, 0.

        Although the starting sequence number must be specified by a literal number, the value can be overridden in the local environment by the LocalEnvironment.Sequence.StartOfSequenceNumber variable.

        The start of sequence message is indicated in the local environment by the LocalEnvironment.Sequence.Start variable, which takes a Boolean value.

      • Set the End of sequence definition property to one of the following values:
        • Automatic with the required timeout value; for example, 60. This value specifies that the sequence group is closed automatically when the message queue in the node has been empty for 60 seconds.
        • Literal with the required end value; for example, 100. This value specifies that the sequence group is closed when the message with the sequence number 100 is processed.
        • Predicate with the required XPATH expression; for example, $InputBody/doc/endFlag. This value specifies that the sequence group is closed when the $InputBody/doc/endFlag predicate evaluates to True ($InputBody/doc/endFlag=True).

        The end of sequence message is indicated in the local environment by the LocalEnvironment.Sequence.End variable, which takes a Boolean value.

    2. On the Advanced tab, set the Persistence mode property to Non-persistent.
      Select Persistent if you want the sequence to be preserved if the queue manager is restarted.
  6. On the MQOutput node, set the Queue name property (on the Basic tab) to the name of a WebSphere® MQ queue to which the MQOutput node sends messages. For example: SEQ.TASK1.OUT1.
  7. Save your message flow.