Watching a Directory and Sending Files with MQ File Mover (How To #5)

In this blog posting, I will show you how to configure MQ File Mover to watch a directory for new files and send the new files immediately. In this example, MQ File Mover will connect to the queue manager in “client mode”.

In the MQ File Mover’s Watch Action, the user can specify all files (‘*’) or select particular files by their file extension (i.e. txt) to be sent by the action.


In this example, the following servers are used but they only have WebSphere MQ (WMQ) Client installed (no queue managers):
– aix002 is an AIX server with WMQ Client and MQFM software installed
– linux002 is a Linux server with WMQ Client and MQFM software installed

In this example, the following queue managers are used:
MQA1 is a queue manager residing on a AIX (aix001) server (sender)
MQL1 is a queue manager residing on a Linux (linux001) server (receiver)

TEST.LINUX.QL and TEST.LINUX.QL.BK are local queues defined in queue manager MQL1 (receiver)
TEST.LINUX.QR is a remote queue defined in queue manager MQA1 (sender)

If you do not know how to define/setup communication between 2 queue managers then follow the instructions in this blog posting:
http://www.capitalware.biz/rl_blog/?p=509

Step #1: On the linux002 server, create a file in the mq directory called mql1.xml and copy the following into the file:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE MQFM_MQ SYSTEM "MQFM_MQ.dtd">
<MQFM_MQ>
    <QMgrName>MQL1</QMgrName>
    <QueueName>TEST.LINUX.QL</QueueName>
    <Hostname>linux001</Hostname>
    <ChannelName>SYSTEM.DEF.SVRCONN</ChannelName>
    <Port>1414</Port>
    <UserID>tester</UserID>
</MQFM_MQ>

The mql1.xml (MQFM_MQ XML) file describes how to connect to the remote MQL1 queue manager on server linux001. The connection will use UserID of tester. If you do not have that UserID defined on the linux001 server then use a UserID that is defined.

Step #2: On the linux002 server, in the MQFM install directory, create a file called mqfm_receive_test_5.xml and copy the following into the file:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE MQFM_Workflow SYSTEM "MQFM_Workflow.dtd">
<MQFM_Workflow>

  <Actions>
    <Receive run="D" >
      <MQ>
        <MQFile>mql1.xml</MQFile>
        <BackOutQName>TEST.LINUX.QL.BK</BackOutQName>
      </MQ>
      <Default>
         <Directory override="Y">/home/roger/MQFM/</Directory>
      </Default>
    </Receive>
  </Actions>

</MQFM_Workflow>

When MQFM is started, it will run as a daemon (run=”D”) and use a backout queue called TEST.LINUX.QL.BK just in case there is an issue with a message. MQFM will override the message’s specified directory and use the one provided. Either create /home/roger/MQFM/ directory on your Linux server or use a directory that already exist on your Linux server.

Step #3: On the linux002 server, start MQFM to receive the file transfers:

./mqfm.sh mqfm_receive_test_5.xml &

Step #4: On the aix002 server, create a file in the mq directory called mqa1.xml and copy the following into the file:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE MQFM_MQ SYSTEM "MQFM_MQ.dtd">
<MQFM_MQ>
    <QMgrName>MQA1</QMgrName>
    <QueueName>TEST.LINUX.QR</QueueName>
    <Hostname>aix001</Hostname>
    <ChannelName>SYSTEM.DEF.SVRCONN</ChannelName>
    <Port>1414</Port>
    <UserID>tester</UserID>
</MQFM_MQ>

The mqa1.xml (MQFM_MQ XML) file describes how to connect to the remote MQA1 queue manager on server aix001. The connection will use UserID of tester. If you do not have that UserID defined on the aix001 server then use a UserID that is defined.

Step #5: On the AIX server, in the watch directory, create a file called watch_1.xml and copy the following into the file:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE MQFM_Watch SYSTEM "MQFM_Watch.dtd">

<MQFM_Watch>

  <PollInterval>15</PollInterval>

  <Watch type="D">
    <Directory>/appdata/mystuff/test</Directory>
    <Extension>txt</Extension>
    <Extension>dat</Extension>
  </Watch>

</MQFM_Watch>

The above MQFM_Watch XML file will tell MQFM to continuously (every 15 seconds) watch directory /appdata/mystuff/test/ for any files that arrive with the extensions of either ‘txt’ or ‘dat’. When either of these file types arrive, MQ File Mover will immediately send those files.

Step #6: On the AIX server, in the MQFM install directory, create a file called mqfm_watch_test_1.xml and copy the following into the file:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE MQFM_Workflow SYSTEM "MQFM_Workflow.dtd">
<MQFM_Workflow>

  <Actions>
    <Watch xmlfile="watch_1.xml" delete="N" format="N">
      <MQ>
        <MQFile>mqa1.xml</MQFile>
      </MQ>
      <Remote>
        <Directory>/var/mqm/</Directory>
      </Remote>
    </Watch>  
  </Actions>

</MQFM_Workflow>

When MQFM is started, the Watch Action will run forever. The MQ File Mover Watch Action will watch the specified directory for those items listed in the watch_1.xml file.

Step #7: On the aix002 server, start MQFM to begin monitoring for files:

./mqfm.sh mqfm_watch_test_1.xml &

MQFM will start, watch for files to arrive in the specified directory. Note: To stop the Watch Action, the user will need to use the Ctl-C or kill command.

Step #8: On the linux002 server, verify that the test file was put into the /home/roger/MQFM/ directory or whatever directory you specified in the mqfm_receive_test_5.xml file.

Step #9: Finally, we need to stop MQFM daemon that is running on the linux002 server. In the MQFM install directory, create a file called mqfm_putquit_test_5.xml and copy the following into the file:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE MQFM_Workflow SYSTEM "MQFM_Workflow.dtd">
<MQFM_Workflow>
  <Actions>
    <PutQuit>
      <MQ>
        <MQFile>mql1.xml</MQFile>
      </MQ>
    </PutQuit>
  </Actions>
</MQFM_Workflow>

Step #10: On the linux002 server, run MQFM with the PutQuit action:

./mqfm.sh mqfm_putquit_test_5.xml

This blog demonstrates how easy it is to watch a directory for files to arrive then immediately send the files using MQFM.

Remember, when possible, use the compression option for the Watch Action to speed up the transfer time and reduce the load placed on MQ You can combine both encryption and compression when sending files (any size) using MQFM.

Regards,
Roger Lacroix
Capitalware Inc.

This entry was posted in Capitalware, IBM i (OS/400), IBM MQ, Java, Linux, macOS (Mac OS X), MQ File Mover, Open Source, Unix, Windows.

Comments are closed.