Quick Reference For MQ Triggering

For More detailed information MQ TRIGGERING click below 

 http://webspherepundit.com/?p=1605


These are the quick references for setting up simple TRIGGERING with few different examples for FIRST , EVERY and DEPTH Modes


Example1 :To start the http process on a First message put in the Queue

NOTE : The method to stop/start http as mqm is not covered in this tutorial .
Http Process is just used for example .. you can use any process as per your requirement ( Ensure that mqm user should be able to stop/start those processes)

——- Start QMgr
bash-3.2$ strmqm QMC01                     

bash-3.2$ runmqsc QMC01

——- Create Initiation Queue
DEFINE QL(TRIGGER.INITIATION.QUEUE) like SYSTEM.DEFAULT.INITIATION.QUEUE

——- Create Local Queue with Triggering Options with TRIGTYPE(FIRST)
DEFINE QLOCAL(TRIGGER.Q) TRIGGER TRIGDPTH(1) TRIGTYPE(FIRST) INITQ(TRIGGER.INITIATION.QUEUE) PROCESS(TRIG.PROCESS)

——- Create Process with APPLICID ( /etc/init.d/httpd start ) It can be any process as per env 
DEFINE PROCESS (‘TRIG.PROCESS’) APPLTYPE(UNIX) APPLICID(‘/etc/init.d/httpd start’)
 

——- Display QueueDepth before testing to ensure there are no messages in the QUEUE
bash-3.2$ echo “DISPLAY QL(TRIGGER.Q) CURDEPTH TRIGGER ” | runmqsc QMC01

 

——- Run runmqtrm command on the Initiation Queue 
bash-3.2$ runmqtrm -m QMC01 -q TRIGGER.INITIATION.QUEUE

——- Put Messages using amqsput  
bash-3.2$/opt/mqm/sampl/bin/amqsput TRIGGER.Q QMC01

——- On the first message put to the QUEUE the triggering would be fired , view the putty console where runmqtrm is running .. here we will see if the trigger event is run and triggering invoked and http process started

——- Display QueueDepth 
bash-3.2$ echo “DISPLAY QL(TRIGGER.Q) CURDEPTH TRIGGER ” | runmqsc QMC01

——- Check if the http Process is saterted by the just putting the Message in Queue
bash-3.2$ps –ef | grep http

 

 

Example2:  Enable triggering to start a unix script with a receipt of a message .
In this example we will be running a script instead of starting a process with trigerring set for FIRST( ie On the arrival of the first message )

——- Create a script when run will browse the message using amqsgbr and redirect to a script.log
bash-3.2$ vi /var/mqm/testscript.sh
############################
echo `date` >> /var/mqm/script.log
/opt/mqm/samp/bin/amqsgbr TRIGGER.Q QMC01 | grep “[1-9] <” >> /var/mqm/script.log
echo “==========================” >> /var/mqm/script.log
############################

——- Make the script executable 
bash-3.2$ chmod 755 /var/mqm/testscript.sh

——- Start Queue Manager
bash-3.2$ strmqm QMC01
bash-3.2$ runmqsc QMC01

——- Create an Initiation Queue 
DEFINE QL(TRIGGER.INITIATION.QUEUE) like SYSTEM.DEFAULT.INITIATION.QUEUE

——- Create a Local Queue where Triggering is enabled with TRIGTYPE(FIRST)
DEFINE QLOCAL(TRIGGER.Q) TRIGGER TRIGDPTH(1) TRIGTYPE(FIRST)  INITQ(TRIGGER.INITIATION.QUEUE) PROCESS(TRIG.PROCESS)

——- Create Process with APPLICID /var/mqm/testscript.sh ie run testscript.sh on triggering
DEFINE PROCESS (‘TRIG.PROCESS’) APPLTYPE(UNIX) APPLICID(‘/var/mqm/testscript.sh‘)

——- Run runmqtrm command for the Initiation Queue 
bash-3.2$ runmqtrm -m QMC01 -q TRIGGER.INITIATION.QUEUE

——- Display QueueDepth before testing to ensure there are no messages in the QUEUE
bash-3.2$ echo “DISPLAY QL(TRIGGER.Q) CURDEPTH TRIGGER ” | runmqsc QMC01 | grep CURDEPTH

——- Put Messages using amqsput
bash-3.2$/opt/mqm/sampl/bin/amqsput TRIGGER.Q QMC01

——- On the first message put to the QUEUE the triggering would be fired and and the script testscript.sh is run . view the putty console where runmqtrm is running .. here we will see if the trigger event is run and triggering invoked
Also The script.log will let us know if it has run properly and triggering invoked.

——- Display QueueDepth 
bash-3.2$ echo “DISPLAY QL(TRIGGER.Q) CURDEPTH TRIGGER ” | runmqsc QMC01 | grep CURDEPTH

——- Check the script.log for ensuring the testscript.sh has run properly due to triggering
bash-3.2$tail -f /var/mqm/script.log

 

 


Example3 :We will Test the Triggering method for
EVERY Message instead of the FIRST message entering the Trigger queue

——- Create a script when run will browse the message using amqsgbr and redirect to a script.log
bash-3.2$ vi /var/mqm/testscript.sh
############################
echo `date` >> /var/mqm/script.log
/opt/mqm/samp/bin/amqsgbr TRIGGER.Q QMC01 | grep “[1-9] <” >> /var/mqm/script.log
echo “==========================” >> /var/mqm/script.log
############################——- Make the script executable 
bash-3.2$ chmod 755 /var/mqm/testscript.sh——- Start Queue Manager
bash-3.2$ strmqm QMC01
bash-3.2$ runmqsc QMC01——- Create an Initiation Queue 
DEFINE QL(TRIGGER.INITIATION.QUEUE) like SYSTEM.DEFAULT.INITIATION.QUEUE

——- Create Process with APPLICID /var/mqm/testscript.sh ie run testscript.sh on triggering
DEFINE PROCESS (‘TRIG.PROCESS’) APPLTYPE(UNIX) APPLICID(‘/var/mqm/testscript.sh‘)

——- Create a Local Queue where Triggering is enabled with TRIGTYPE(EVERY) 
ALTER QLOCAL(TRIGGER.Q) TRIGGER TRIGDPTH(1) TRIGTYPE(EVERY) INITQ(TRIGGER.INITIATION.QUEUE) PROCESS(TRIG.PROCESS)

——- Run runmqtrm command for the Initiation Queue
bash-3.2$ runmqtrm -m QMC01 -q TRIGGER.INITIATION.QUEUE

——- Display QueueDepth before testing to ensure there are no messages in the QUEUE
bash-3.2$ echo “DISPLAY QL(TRIGGER.Q) CURDEPTH TRIGGER ” | runmqsc QMC01 | grep CURDEPTH

——- Put Messages using amqsput , Put 3 messages to test
/opt/mqm/sampl/bin/amqsput TRIGGER.Q QMC01

——- For every Message put in the Queue TRIGGER.Q , a trigger event would start and the script would run 3 times and the output captured in script.log . View the putty console where runmqtrm is running .. here we will see if the trigger event is run and triggering invoked

——- Display QueueDepth before testing to ensure there are no messages in the QUEUE
bash-3.2$ echo “DISPLAY QL(TRIGGER.Q) CURDEPTH TRIGGER ” | runmqsc QMC01 | grep CURDEPTH

——- Check the script.log for ensuring the testscript.sh has run properly due to triggering
bash-3.2$tail -f /var/mqm/script.log


Example4 :We will test the triggering for the Depth of the Queue ie when the QUEUE Depth reaches the defined setting a triggering should be fired

——- Create a script when run will browse the message using amqsgbr and redirect to a script.log
bash-3.2$ vi /var/mqm/testscript.sh
############################
echo `date` >> /var/mqm/script.log
/opt/mqm/samp/bin/amqsgbr TRIGGER.Q QMC01 | grep “[1-9] <” >> /var/mqm/script.log
echo “==========================” >> /var/mqm/script.log
############################ 

——- Make the script executable
bash-3.2$ chmod 755 /var/mqm/testscript.sh

 

——- Start Queue Manager
bash-3.2$ strmqm QMC01
bash-3.2$ runmqsc QMC01——- Create an Initiation Queue 
DEFINE QL(TRIGGER.INITIATION.QUEUE) like SYSTEM.DEFAULT.INITIATION.QUEUE

——- Create Process with APPLICID /var/mqm/testscript.sh ie run testscript.sh on triggering
DEFINE PROCESS (‘TRIG.PROCESS’) APPLTYPE(UNIX) APPLICID(‘/var/mqm/testscript.sh‘)

——- Create a Local Queue where  Triggering is enabled
ALTER QLOCAL(TRIGGER.Q) TRIGGER TRIGDPTH(3) TRIGTYPE(DEPTH) INITQ(TRIGGER.INITIATION.QUEUE) PROCESS(TRIG.PROCESS)

——- Run runmqtrm command for the Initiation Queue
bash-3.2$ runmqtrm -m QMC01 -q TRIGGER.INITIATION.QUEUE

——- Display QueueDepth before testing to ensure there are no messages in the QUEUE
bash-3.2$ echo “DISPLAY QL(TRIGGER.Q) CURDEPTH TRIGGER ” | runmqsc QMC01 | grep CURDEPTH

——- Put 3 Messages in the TRIGGER.Q  using amqsput
/opt/mqm/sampl/bin/amqsput TRIGGER.Q QMC01

——- Display QueueDepth before testing to ensure there are no messages in the QUEUE
bash-3.2$ echo “DISPLAY QL(TRIGGER.Q) CURDEPTH TRIGGER ” | runmqsc QMC01 | grep CURDEPTH

——- Only onces the Depth of the QUEUE has reached to the TRIGDPTH ie “3” messages the triggering will be invoked. It can be seen from the putty console of “runmqtrm”  and also visible from the /var/mqm/script.log the triggering result 

——- Check the script.log for ensuring the testscript.sh has run properly due to queue depth triggering
bash-3.2$tail -f /var/mqm/script.log

——- After the triggering is fired the Triggering for the QUEUE “TRIGGER.Q” in the Example , It gets disabled ..

——- It needs to be Re-Enabled using below command or use MQSET to renable the TRIGERR from the Application.

——- So for every time trigger is invoked due to QUEUE DEPTH ( TRIGDPTH ) the Triggering needs to be enabled again 

——- Reenable the Triggering for the TRIGGER.Q
bash-3.2$ echo “ALTER QLOCAL(TRIGGER.Q) TRIGGER ” | runmqsc QMC01

 

Example4 :Runmqtrm as a SERVICE

 

——- Start Queue Manager
bash-3.2$ strmqm QMC01
bash-3.2$ runmqsc QMC01
 

——- Define Service for TRIGGER Monitor
DEFINE SERVICE(TRIGMON) CONTROL(QMGR) SERVTYPE(SERVER) +
STARTCMD(‘+MQ_INSTALL_PATH+bin/runmqtrm’) +
STARTARG(‘-m +QMNAME+ -q SYSTEM.DEFAULT.INITIATION.QUEUE’) +
STOPCMD(‘+MQ_INSTALL_PATH+bin/amqsstop’) +
STOPARG(‘-m +QMNAME+ -p +MQ_SERVER_PID+’) STDOUT(‘/tmp/TrigMon.stdout’) +
STDERR(‘/tmp/TrigMon.stderr’)

 

——- Start the Service
START SERVICE(TRIGMON)

 

——- View the Services attributes
DISPLAY SVSTATUS(TRIGMON)

 

——- Triggering Std Out and Error
bash-3.2$ ls -lt /tmp/Trig*
-rw-r–r– 1 mqm mqm 239 2014-03-20 13:18 /tmp/TrigMon.stdout
-rw-r–r– 1 mqm mqm 0 2014-03-20 13:18 /tmp/TrigMon.stderr

 

 

To get automated mail updates of my Posts..
Please subscribe to the site http://webspherepundit.com
And also like the Facebook Page
https://www.facebook.com/webspherepundit

 

Leave a Reply

Your email address will not be published. Required fields are marked *