MQ Trigering
=========
=> What is Triggering?
WebSphere MQ provides a feature that enables an application or channel to be started automatically when there are messages available to retrieve from a queue.
=> How it works?
- A message is put to a queue defined as triggered.
- If a series of conditions are met, the queue manager sends a trigger message to an initiation queue. This is called a trigger event.
- A trigger monitor reads the trigger message and takes the appropriate action based on the contents of the message, which is typically to start a program to process the triggered queue.
- Trigger monitors may be built-in, supplied by a SupportPac, or user written.
=> Types of Trigger (TRIGTYPE)
- FIRST: A trigger event occurs when the current depth of the triggered queue changes from 0 to 1.
Use this type of trigger when the serving program will process all the messages on the queue (i.e. until MQRC_NO_MSG_AVAILABLE).
- EVERY: A trigger event occurs every time a message arrives on the triggered queue.
Use this type of trigger when the serving program will only process one message at a time.
- DEPTH: A trigger event occurs when the number of messages on the triggered queue reaches the value of the TRIGDPTH attribute.
Use this type of trigger when the serving program is designed to process a fixed number of messages (i.e. all replies for a certain request).
=> Trigger interval (TRIGINT)
- TriggerInterval or TRIGINT is a time interval specified on the QMGR definition for use by queues defined as TRIGTYPE=FIRST.
- Situations may occur when messages are left on the queue. New messages will not cause another trigger message. To help with this situation, a trigger message will be created when the next message is put if TriggerInterval has elapsed since the last trigger message was created for the queue.
=> Trigget setup
- Create an initiation queue or use the default SYSTEM.CHANNEL.INITQ.
- Create a process definition (optional). TriggerData may be specified in lieu of a process definition.
- Create or alter a transmission queue.
- Associate the initiation queue and the process definition (if applicable) with the transmission queue, and specify the trigger attributes.
=> Triggering Example1
- DEFINE QLOCAL(QM2) REPLACE USAGE (XMITQ) TRIGGER TRIGTYPE(FIRST) TRIGDATA(QM1.TO.QM2) INITQ (SYSTEM.CHANNEL.INITQ)
- QM2 is the name of the XMITQ
- QM1.TO.QM2 is the name of the channel to be started when a message hits the XMITQ
- SYSTEM.CHANNEL.INITQ is the initq monitored by the channel initiator
=> Triggering Example2
- DEFINE QLOCAL(QM4) TRIGGER INITQ(SYSTEM.CHANNEL.INITQ) PROCESS(P1) USAGE (XMITQ) ? DEFINE PROCESS(P1) USERDATA(QM3.TO.QM4)
- The XMITQ definition has PROCESS instead of TRIGDATA
- The channel name is in USERDATA
=> Application Triggering
- Create an initiation queue or use the default SYSTEM.DEFAULT.INITIATION.QUEUE.
- Create a process definition.
- Create or alter a local or model queue.
- Associate the initiation queue and process definition with the local queue, and specify the trigger attributes .
APPLICID is the name of the application executable file, e.g.
- For APPLTYPE(UNIX):
APPLICID (’/u/admin/test/IRMP01′)
- For APPLTYPE(WINDOWSNT):
APPLICID(‘c:\appl\test\irmp01.exe.’)
- On UNIX® systems, ENVRDATA can be set to the ampersand character to make the started application run in the background.
- The application can receive a parm list with an MQTMC2 containing USRDATA and ENVRDATA.
=> Application Trigger Example1
- DEFINE QLOCAL (‘IQ’) REPLACE
- DEFINE PROCESS (PROC) REPLACE APPLTYPE (’CICS’) APPLICID (’PAYR’) USERDATA (’Payroll data’)
- DEFINE QLOCAL (Q1) REPLACE INITQ (‘IQ’) PROCESS (‘PROC’) TRIGGER TRIGTYPE (FIRST)
- Note: If using TRIGTYPE(DEPTH) then TRIGDEPTH must also be specified.
=> Application Trigger Example2
- CRTMQMQ QNAME(initq_name)
- CRTMQMPRC PRCNAME(proc_name) APPID(lib/pgm) ENVDATA (‘JOBNAME(trigapl) JOBD(lib/jobd)’)
- CRTMQMQ QNAME(lclq_name) PRCNAME (proc_name) TRGENBL(*YES) TRGTYPE(*FIRST) INITQNAME(initq_name)
- Note: If using TRGTYPE(*DEPTH) then TRGDEPTH must also be specified.
=> Trigger Conditions
- A trigger message is sent to the initiation queue when all of the following conditions are satisfied:
1. A message is put on a transmission or local queue.
2. The message’s priority is greater than or equal to the TriggerMsgPriority of the queue.
3. The number of messages on queue was previously
- Zero for trigger type FIRST
- Any number for trigger type EVERY or *ALL
- TriggerDepth minus 1 for trigger type DEPTH
4. For trigger type FIRST or DEPTH, no program has the trigger queue open for GETs (Open input count=0).
5. The Get enabled attribute is set to YES on the triggered queue.
6. A Process name is specified and exists, or for transmission queues, TriggerData contains the name of a channel.
7. An Initiation queue is specified and exists and GETs and PUTs are enabled for the initiation queue.
8. The trigger monitor has been started and has the initiation queue open for GETs
9. The TriggerControl attribute is set to YES on the triggered queue.
10. The TriggerType attribute is not set to NONE.
11. For Trigger Type FIRST, the queue was not previously empty, but the TriggerInterval set for the QMGR has elapsed.
12. The only application serving the queue issues MQCLOSE and there are still messages on the queue that satisfy Conditions 2 and 6-10.
13. Certain trigger attributes of the triggered queue are changed, such as
- NOTRIGGER to TRIGGER
- PUT or GET DISABLED to ENABLED
- or a trigger monitor opens the Initiation queue.
14. MSGDLVSQ is set correctly relative to the priority of the messages and the TriggerMsgPriority setting.
=> Triggering Problem determination
- If the setup is brand new or any configuration changes have been made, verify all the definitions are complete and correct.
- If the setup is brand new or has worked before, verify all the conditions for a trigger event are satisfied.
- If channel triggering, verify the correct channel name is specified and the channel is not in a STOPPED state.
- If application triggering
- verify the application name is correct and exists
- verify the application is coded correctly
- verify the correct authorizations are in place.
- Verify a trigger message can be delivered.
- Verify a trigger monitor is active.
- Verify trigger type and application design match.
- Try manually starting the triggered application to see if it is able to run.
- Stranded messages may occur when the triggered application fails to remove one or more messages
- for TriggerType FIRST, use TriggerInteval as a “safety net”, because a trigger event only occurs when depth goes from 0 to 1.
- for TriggerType EVERY, if the triggered application only does one MQGET, manual intervention will be required to process the messages. Otherwise, the application will only read the oldest message on the next successful trigger and the queue depth will remain non-zero.
- If there is a loop or high CPU:
- Change the triggered application to specify a WaitInterval on its MQGET.
- Check the BackoutCount in the MQMD
=> TIPS
- For trigger EVERY, if the trigger monitor ends prematurely, no matter how many messages reside on the queue only one trigger message will be created on restart.
- RUNMQTRM will not get another trigger message until the application completes. To prevent trigger messages from accumulating
- Run multiple trigger monitors or
- Run the applications in the background
- A trigger message is put to the dead letter queue when
- The queue manager can not put a trigger message on the INITQ
- RUNMQTRM detects an error in the trigger message structure
- RUNMQTRM detects an unsupported application type
- RUNMQTRM can not start the application
- RUNMQTRM detects a data conversion error
- Trigger messages are non-persistent.
- Conditions for a trigger event are “persistent”, so, if a trigger message is lost a trigger message will be created when the conditions are met.
- Trigger messages take on the default priority of the INITQ.
- Trigger monitors can not retrieve messages that are part of a unit of work until the unit of work completes (applies whether it is committed or backed out).
- The queue manager counts both committed and uncommitted messages on the trigger queue when assessing the conditions for a trigger event.
- After recycling the queue manager or trigger monitor, a trigger message may be created if the triggered queue has messages on it and provided the trigger conditions are met.
- When triggering channels, trigger type FIRST or DEPTH is recommended.
- Disabling triggering is not under syncpoint control so triggering can not be re-enabled by backing out a unit of work. If a program backs out a unit of work or abends, triggering for DEPTH must be reenabled by MQSET, ALTER or CHGMQMQ.
No comments:
Post a Comment