Monitoring a queue and using variable substitution

You can monitor a queue and transfer messages from the monitored queue to a file using the fteCreateMonitor command. The value of any WebSphere® MQ message property in the first message to be read from the monitored queue can be substituted in the task XML definition and used to define the transfer behavior.

About this task

In this example, the source agent is called AGENT_VENUS, which connects to QM_VENUS. The queue that AGENT_VENUS monitors is called START_QUEUE and is located on QM_VENUS. The agent polls the queue every 30 minutes.

When a complete group of messages is written to the queue the monitor task sends the group of messages to a file at one of a number of destination agents, all of which connect to the queue manager QM_MARS. The name of the file that the group of messages is transferred to is defined by the WebSphere MQ message property usr.fileName on the first message in the group. The name of the agent that the group of messages is sent to is defined by the WebSphere MQ message property usr.toAgent on the first message in the group. If the usr.toAgent header is not set, the default value to be used for the destination agent is AGENT_MAGENTA.

Procedure

  1. Create the task XML that defines the task that the monitor performs when it is triggered.
    <?xml version="1.0" encoding="UTF-8" ?>
    <request version="4.00" 
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
             xsi:noNamespaceSchemaLocation="FileTransfer.xsd">
       <managedTransfer>
         <originator>
           <hostName>reportserver.com</hostName>
           <userID>USER1</userID>
         </originator>
         <sourceAgent agent="AGENT_VENUS" QMgr="QM_VENUS" />
         <destinationAgent agent="${toAgent}" QMgr="QM_MARS" />
         <transferSet>
           <item mode="binary" checksumMethod="none">
             <source>
               <queue>START_QUEUE</queue>
             </source>
             <destination type="file" exist="overwrite">
               <file>/reports/${fileName}.rpt</file>
             </destination>
           </item>
         </transferSet>
       </managedTransfer>
    </request>

    The variables that are replaced with the values of WebSphere MQ message headers are highlighted in bold. This task XML is saved to the file /home/USER1/task.xml

  2. Create a resource monitor to monitor the queue START_QUEUE. Submit the following command:
    fteCreateMonitor -ma AGENT_VENUS -mm QM_VENUS -mq START_QUEUE 
                     -mn myMonitor -mt /home/USER1/task.xml 
                     -tr completeGroups -pi 30 -pu minutes -dv toAgent=AGENT_MAGENTA
  3. A user or program writes a group of messages to the queue START_QUEUE. The first message in this group has the following WebSphere MQ message properties set:
    usr.fileName=larmer
    usr.toAgent=AGENT_VIOLET
  4. The monitor is triggered when the complete group has been written. The agent substitutes the WebSphere MQ message properties into the task XML. This results in the task XML being transformed to:
    <?xml version="1.0" encoding="UTF-8" ?>
    <request version="4.00" 
             xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance 
             xsi:noNamespaceSchemaLocation="FileTransfer.xsd">
       <managedTransfer>
         <originator>
           <hostName>reportserver.com</hostName>
           <userID>USER1</userID>
         </originator>
         <sourceAgent agent="AGENT_VENUS" QMgr="QM_VENUS" />
         <destinationAgent agent="AGENT_VIOLET" QMgr="QM_MARS" />
         <transferSet>
           <item mode="binary" checksumMethod="none">
             <source>
               <queue>START_QUEUE</queue>
             </source>
             <destination type="file" exist="overwrite">
               <file>/reports/larmer.rpt</file>
             </destination>
           </item>
         </transferSet>
       </managedTransfer>
    </request>

Results

The transfer defined by the task XML is performed. The complete group of messages read from the START_QUEUE by AGENT_VENUS is written to a file called /reports/larmer.rpt located on the system where AGENT_VIOLET is running.

Task Task

Feedback

Timestamp icon Last updated: Tuesday, 30 January 2018
http://www.ibm.com/support/knowledgecenter/SSEP7X_7.0.4/com.ibm.wmqfte.doc/m2f_mon_variable.htm