Extending the Message Routing sample using a file

You can modify the Message Routing sample ESQL so that you can use it in other message flows with very few changes.

Changing the cache refresh criteria

The cache is currently refreshed when a refresh message is sent to the ROUTING.REFRESH queue.

Other criteria can be used to decide when to refresh the cache, for example:

To change the criterion, edit the following location in the ESQL:

IF CacheFile.valid IS NOT NULL THEN

To change the refresh criteria to use a time period of 60 seconds:

  1. Change the criteria circled in red in the ESQL to:
    IF CacheFile.LastUpDate is not null and (CURRENT_TIMESTAMP - 
        CacheFile.LastUpDate) second < INTERVAL '60' SECOND THEN
  2. Also change the second instance of
    IF CacheFile.Valid is not null THEN
    to be the same as in the previous step
  3. Change
    SET CacheFile.valid = true;
    to
    SET CacheFile.LastUpDate = CURRENT_TIMESTAMP;

Using offset of record instead of propagate record expression

Currently the sample chooses which record to propagate by setting the record selection expression. It might be the case that each time a message is sent you want to retrieve the next record in the file. This action can be achieved by setting the offset.

Offset property

You can use the offset property in the following way:

  1. In the message flow Routing_using_records_file add two Compute nodes, one before the FileRead node and one after.
  2. In the ESQL create a shared variable:
    declare cache SHARED ROW;
  3. In the ESQL of the first Compute node add the following code:
    SET OutputLocalEnvironment = InputLocalEnvironment;
    		IF (cache.file.offset > 0) THEN
              SET OutputLocalEnvironment.Destination.File.Offset = cache.file.offset;
              ELSE
              SET OutputLocalEnvironment.Destination.File.Offset = 0;
              END IF;	
    		
    Set the Compute mode property to LocalEnvironment.
  4. In the ESQL of the second Compute node add the following code:
    SET OutputLocalEnvironment = InputLocalEnvironment;
    SET cache.file.offset = OutputLocalEnvironment.File.Read.NextRecordOffset;
    Set the Compute mode property to LocalEnvironment.
  5. On the FileRead node, set the Record selection expression property to true()
  6. To drive the message flow use File_Records_file_message1.mbtest and click enqueue multiple times. This will read in each record in turn.

Using route to label instead of queue

The sample shows how to route a message to a particular queue. Another usage might be routing to a label. To implement this use the following instructions:

  1. In the message flow, Routing_using_records_file, on the FileRead node change the Output data location property to $OutputLocalEnvironment/Destination/RouterList/DestinationData/labelName
  2. Change the Result data location property to $ResultRoot/MRM/data/labelName. Change the Message set property from queueName to labelName.
  3. Add a RouteToLabel node after the FileRead node, and remove the MQOutput node.
  4. Add several Label nodes.
  5. Update fileRead.csv and change the queue names to label names.
  6. Set the Label Name properties on each of the Label nodes to the names of the labels you set in fileRead.csv.
  7. After each Label node add an MQOutput node and specify the queue name.

You can replace the MQOutput nodes with other types of output node. For example, use a flow using a RouteToLabel node:

Route To label

Back to sample home