home / infca / mq / mq_trig (navigation links) God made everything out of nothing,  
but the nothingness shows through  
Paul Valery  

Trigger a SDR channel | Trigger a server app Links | End | mapa

Triggering under MQ


What is triggering?

[MQ Application Programming Guide, SC34-6064-02, page 191, 213/643]  

The queue manager defines certain conditions as constituting trigger events. If triggering is enabled for a queue and a trigger event occurs, the queue manager sends a trigger message to a queue called an initiation queue. The presence of the trigger message on the initiation queue indicates that a trigger event has occurred.

Trigger messages generated by the queue manager are not persistent. This has the effect of reducing logging (thereby improving performance), and minimizing duplicates during restart, so improving restart time.

The program which processes the initiation queue is called a trigger-monitor application, and its function is to read the trigger message and take appropriate action, based on the information contained in the trigger message. Normally this action would be to start some other application to process the queue which caused the trigger message to be generated. From the point of view of the queue manager, there is nothing special about the trigger-monitor application; it is simply another application that reads messages from a queue (the initiation queue).

If triggering is enabled for a queue, you have the option to create a process-definition object associated with it. This object contains information about the application that processes the message which caused the trigger event. If the process definition object is created, the queue manager extracts this information and places it in the trigger message, for use by the trigger-monitor application. The name of the process definition associated with a queue is given by the ProcessName local-queue attribute. Each queue can specify a different process definition, or several queues can share the same process definition.


Sequence of events

MQ Application Programming Guide, SC34-6064-02, page 194.  


Prerequisites for triggering

MQ Application Programming Guide, SC34-6064-02, page 196.  

Before your application can take advantage of triggering, follow the steps below:

If you wish to be aware of any undelivered trigger messages, make sure your queue manager has a dead-letter (undelivered-message) queue defined. Specify the name of the queue in the DeadLetterQName queue manager field.


When triggering does not work

MQ Application Programming Guide, SC34-6064-02, page 213.  

A program is not triggered if the trigger monitor cannot start the program or the queue manager cannot deliver the trigger message. For example, the ApplId in the process object must specify that the program is to be started in the background; if this is not done, the trigger monitor cannot start the program.

If a trigger message is created but cannot be put on the initiation queue (for example, because the queue is full or the length of the trigger message is greater than the maximum message length specified for the initiation queue), the trigger message is put instead on the dead-letter (undelivered message) queue.

If the put operation to the dead-letter queue cannot complete successfully, the trigger message is discarded and a warning message is sent to the console (z/OS) or to the system operator (iSeries), or put on the error log.

Putting the trigger message on the dead-letter queue may generate a trigger message for that queue. This second trigger message is discarded if it adds a message to the dead-letter queue.

If the program is triggered successfully but abends before it gets the message from the queue, use a trace utility (for example, CICS AUXTRACE if the program is running under CICS) to find out the cause of the failure.

Compte !

Quizás en la DLQ hay MQFB_APPL_CANNOT_BE_STARTED !

Let's make it run [T42]

UNO.EXE

amqsput Q3SAG Q3 :

If I change "Trigger Monitor" parameter Queue Name to "Q3SAG", then, on every message I put there, I get MQFB_TM_ERROR

MQFB_TM_ERROR - MQTM structure not valid or missing.
The Format field in MQMD specifies MQFMT_TRIGGER, but the message does not begin with a valid MQTM structure. For example, the StrucId mnemonic eye-catcher may not be valid, the Version may not be recognized, or the length of the trigger message may be insufficient to contain the MQTM structure.


WR2FI.EXE


\\MQ\Eines\TrigCode\mycode.c

Cliente : T42 VM("MB", ip=192.168.157.129 [HostNet], mq v 5.3)

Requerimientos :

Servidor : T42 VM("GNI", ip=192.168.157.128 [HostNet], mq v 6.0)

Requerimientos :

Acción : ponemos un mensaje en SAGDATQ de QM1.
Reacción : aparece traza en SAG_TRIG.TRC.


Another sample here.


Triggering a Sender channel

In order to start a sender channel when a message comes to its transmit queue, use the following :

 def ql(DESA4) usage(xmitq) maxmsgl(104857600) + 
     trigger TRIGTYPE(EVERY) TRIGDPTH(1) + 
     trigdata(DESA3.DESA4) +               /* channel name */ 
     initq(SYSTEM.CHANNEL.INITQ) replace   /* mandatory */ 
 

Amunt! Top Amunt!
Trigger a "server" application

(1) Modifiquem la cua que ha de rebre les dades :

DEFINE QLOCAL('QL.IN') + TRIGGER + TRIGTYPE (FIRST) INITQ('QL.TRIGGER_MSGS') + PROCESS('MY_PROCESS') REPLACE

(2) Crear la cua per rebre els events de trigger :

DEFINE QLOCAL('QL.TRIGGER_MSGS') REPLACE

(3) Crear el procés que s'engegarà en rebre les dades

DEFINE PROCESS('MY_PROCESS') + USERDATA('PARAM1 PARAM2') + APPLICID('c:\mypath\myprog.exe') REPLACE APPLICID('c:\sebas\MQ\Eines\AMQSECHA_modificat-Envia_Resposta\AMQSECHA.EXE') replace

(4-a) Provar que funciona amb un Trigger Monitor en una Command Line :

start runmqtrm -m QMN -q QL.TRIGGER_MSGS

posant missatges : amqsput QL.IN QMN

(4-b) Automatitzar el conjunt :

DEFINE SERVICE('TRIG_MON_START') + CONTROL(QMGR) + SERVTYPE(SERVER) + STARTCMD('/opt/mqm/bin/runmqtrm') + o 'c:\MQ\bin\runmqtrm.exe' en guindous STARTARG('-m +QMNAME+ -q "QL.TRIGGER_MSGS"') + STOPCMD('c:\MQ\bin\amqsstop.exe') + STOPARG('-m +QMNAME+ -p +MQ_SERVER_PID+') + STDOUT('C:\temp\trigger_monitor_out.txt') + STDERR('C:\temp\trigger_monitor_err.txt') + replace

Otherwise, you receive "AMQ8739: Stop cannot be executed for service with blank STOPCMD."

Sys Admin Guide


Amunt! Top Amunt!
Starting a trigger monitor from MQ Explorer

To start a trigger monitor from MQ Explorer, you must first create a service that will run the runmqtrm command (to start the trigger monitor) when the service starts. Note that if you are starting a trigger monitor for a client, use the runmqtmc command instead.

To create the trigger monitor service:

  1. In the Navigator view, expand the queue manager on which you want to start the trigger monitor service.
  2. Right-click the queue manager's Services folder, then click New... > Service. The New Service dialog opens.
  3. In the New Service dialog, type a name for the service, for example, TriggerMonitor, then click Next. You can now configure the new service.
  4. Optional: In the Service desc field, type a description of the service, for example "A trigger monitor for queue manager QM1".
  5. Configure how the service starts and stops:
    • To start and stop the service automatically when the queue manager starts and stops, click Queue Manager
    • To start the service automatically when the queue manager starts but not to stop when the queue manager stops, click Queue Manager Start
    • To configure the service so that you must manually start and stop it, click Manual.
  6. In the Start Command field, type the full path to the runmqtrm command.
    • On Windows, type: install_dir\WebSphere MQ\bin\runmqtrm where install_dir is the location in which MQ is installed on the computer.
    • On Linux, type: /opt/mqm/bin/runmqtrm
  7. If the queue manager is not the default queue manager, in the Start args field, type -m queue_manager where queue_manager is the name of the queue manager.
  8. If you want to use a queue other than SYSTEM.DEFAULT.INITATION.QUEUE as the initiation queue, in the Start args field, type -q initq_name where initq_name is the name of the queue.
  9. In the Service Type field, select the type of service to run:
    • If you select Command type, you can run multiple instances of the service but you cannot view the status of the service in MQ Explorer.
    • If you select Server type, you can run only one instance of the service but you can view the status of the service in MQ Explorer.
  10. Click Finish.

The new service is created on the selected queue manager.

To start the trigger monitor using the service that you previously created:

  1. In the Navigator view, click the Services folder to display the services on queue manager, in the Content view.
  2. In the Content view, right-click the service, then click Start.

The service starts and runs the runmqtrm command, which starts the trigger monitor on the queue manager.

Starting a trigger monitor from Unix service (using objects)

Define the following objects to the queue manager :

DEFINE QL(QL1) TRIGGER INITQ(QT1) PROCESS(RSP) REPLACE DEFINE QL(QT1) REPLACE DEFINE PROCESS(RSP) APPLICID('/home/sebas/mq_cmds/Reply/amqsecha') REPLACE DEFINE SERVICE('TRIG_MON_START') + CONTROL(QMGR) + SERVTYPE(SERVER) + STARTCMD('/opt/mqm/bin/runmqtrm') + STARTARG('-m +QMNAME+ -q "QT1"') REPLACE

More samples

Si volem activar un programa (even Rexx) quan es rebi un missatge en una cua, hem de fer el següent :

  1. a les Propietats de la cua (diguem que es diu AADATAQ), hi posem

    • Trigger Control := "On" ;
    • Trigger Type := "Every" ;
    • Trigger Data := "A1A1A1A1" ;
    • Initiation Queue Name := "AAINITQ" ;
    • Process Name := "SAGpro" ;

  2. la cua de events de Trigger, aquí AAINITQ, ha de ser senzillament de Recepció (Normal).

  3. a "Process Definitions" hi posem
    • Process Definition Name := "SAGpro" ;
    • Application Type := "Windows/NT"
    • Application Identifier := "START /B c:\temp\mq\SAGFER.CMD"
      or "\\mq\eines\trig_code\sag_trig.exe"
    • Environment Data := "B2B2B2B2" ;
    • User Data := "C3C3C3C3" ;

  4. definim un nou "Trigger Monitor" a "WS MQ Services", amb Queue Name := "AAINITQ" a la solapa de "Parameters".

    També ho podem fer des Command-Line :

    start runmqtrm [-m NombGstCola] [-q ColaInic]

    Keep this window up so you can monitor it (see if triggering occurs) !

Compte que si hi posem un AMQSGET AAJOSEQ WFQM > c:\temp\mq\kk.log, te un retard (timeout) de vora un minut !

What is the best way to start or run the trigger monitor automatically when the MQserver starts ?

If you are running NT or 2000, you can set it up through MQSeries Services. With the queue manager running, right click on the queue manager, select new and then trigger monitor. On the 'general' tab, select automatic as the start option.

  Basically, you create a local queue that you want to be triggered. This queue has an initiation queue which indicates where a trigger message gets sent. A trigger monitor then reads from this queue and starts up the process defined in your local queue. There are definitions to create objects for the samples in \mqsc\Samples\amqscos0.txt. My guess is that you have pointed your trigger monitor to your local queue rather than your initiation queue. ... There are details on setting up triggering in either the APR or APG. There are also some samples that are designed to use triggering. Basically, you need to mark your actual queue as triggered and point it to an initiation queue. This queue is then 'watched' by the trigger monitor. When a message is put on your queue, the init queue gets a message and the trigger monitor starts up your application.

Sample [***]


Trigger initiator message

If we define :

Data Queue : TRIGGER PROCESS(hesp) INITQ('INIT_Q') TRIGDPTH(1) TRIGDATA(Trig_Data) TRIGTYPE(FIRST) And Init Queue : DEFINE QLOCAL ('INIT_Q') And Process : PROCESS(hesp) APPLTYPE(WINDOWSNT) APPLICID(START C:\Eines\HIT_OR_OTA.exe) ENVRDATA(Env_Data) USERDATA(Usr_Data)

then we get the following message in the Initiation queue : ( see Header structure here )

00000 54 4D 20 20 01 00 00 00--48 45 53 50 20 20 20 20 |TM ....HESP | 00010 20 20 20 20 20 20 20 20--20 20 20 20 20 20 20 20 | | 00020 20 20 20 20 20 20 20 20--20 20 20 20 20 20 20 20 | | 00030 20 20 20 20 20 20 20 20--68 65 73 70 65 72 69 61 | hesperia| 00040 20 20 20 20 20 20 20 20--20 20 20 20 20 20 20 20 | | 00050 20 20 20 20 20 20 20 20--20 20 20 20 20 20 20 20 | | 00060 20 20 20 20 20 20 20 20--54 72 69 67 5F 44 61 74 | Trig_Dat| 00070 61 20 20 20 20 20 20 20--20 20 20 20 20 20 20 20 |a | 00080 20 20 20 20 20 20 20 20--20 20 20 20 20 20 20 20 | | 00090 20 20 20 20 20 20 20 20--20 20 20 20 20 20 20 20 | | 000A0 20 20 20 20 20 20 20 20--0B 00 00 00 53 54 41 52 | ...STAR| 000B0 54 20 20 20 43 3A 5C 53--65 62 61 73 5C 4D 51 5C |T C:\Sebas\MQ\| 000C0 45 69 6E 65 73 5C 48 49--54 49 53 5F 6F 72 5F 4F |Eines\HITIS_or_O| 000D0 54 41 5C 48 49 54 49 53--5F 4F 52 5F 4F 54 41 2E |TA\HITIS_OR_OTA.| 000E0 65 78 65 20 20 20 20 20--20 20 20 20 20 20 20 20 |exe | 000F0 20 20 20 20 20 20 20 20--20 20 20 20 20 20 20 20 | | 00100 20 20 20 20 20 20 20 20--20 20 20 20 20 20 20 20 | | 00110 20 20 20 20 20 20 20 20--20 20 20 20 20 20 20 20 | | 00120 20 20 20 20 20 20 20 20--20 20 20 20 20 20 20 20 | | 00130 20 20 20 20 20 20 20 20--20 20 20 20 20 20 20 20 | | 00140 20 20 20 20 20 20 20 20--20 20 20 20 20 20 20 20 | | 00150 20 20 20 20 20 20 20 20--20 20 20 20 20 20 20 20 | | 00160 20 20 20 20 20 20 20 20--20 20 20 20 20 20 20 20 | | 00170 20 20 20 20 20 20 20 20--20 20 20 20 20 20 20 20 | | 00180 20 20 20 20 20 20 20 20--20 20 20 20 20 20 20 20 | | 00190 20 20 20 20 20 20 20 20--20 20 20 20 20 20 20 20 | | 001A0 20 20 20 20 20 20 20 20--20 20 20 20 45 6E 76 5F | Env_| 001B0 44 61 74 61 20 20 20 20--20 20 20 20 20 20 20 20 |Data | 001C0 20 20 20 20 20 20 20 20--20 20 20 20 20 20 20 20 | | 001D0 20 20 20 20 20 20 20 20--20 20 20 20 20 20 20 20 | | 001E0 20 20 20 20 20 20 20 20--20 20 20 20 20 20 20 20 | | 001F0 20 20 20 20 20 20 20 20--20 20 20 20 20 20 20 20 | | 00200 20 20 20 20 20 20 20 20--20 20 20 20 20 20 20 20 | | 00210 20 20 20 20 20 20 20 20--20 20 20 20 20 20 20 20 | | 00220 20 20 20 20 20 20 20 20--20 20 20 20 55 73 72 5F | Usr_| 00230 44 61 74 61 20 20 20 20--20 20 20 20 20 20 20 20 |Data | 00240 20 20 20 20 20 20 20 20--20 20 20 20 20 20 20 20 | | 00250 20 20 20 20 20 20 20 20--20 20 20 20 20 20 20 20 | | 00260 20 20 20 20 20 20 20 20--20 20 20 20 20 20 20 20 | | 00270 20 20 20 20 20 20 20 20--20 20 20 20 20 20 20 20 | | 00280 20 20 20 20 20 20 20 20--20 20 20 20 20 20 20 20 | | 00290 20 20 20 20 20 20 20 20--20 20 20 20 20 20 20 20 | | 002A0 20 20 20 20 20 20 20 20--20 20 20 20 | |

How to compile the triggered code

No special flag required.
Sample code can be found here.


Glossary

Book : Intercommunication  

Initiation queue
A local queue on which the queue manager puts trigger messages.

Trigger event
An event (such as a message arriving on a queue) that causes a queue manager to create a trigger message on an initiation queue.

Trigger message
A message containing information about the program that a trigger monitor is to start.

Trigger monitor
A continuously-running application serving one or more initiation queues. When a trigger message arrives on an initiation queue, the trigger monitor retrieves the message. It uses the information in the trigger message to start a process that serves the queue on which a trigger event occurred.

Trigger monitor interface (TMI)
The MQSeries interface to which customer- or vendor-written trigger monitor programs must conform. A part of the MQSeries Framework.


Amunt! Top Amunt!
Did you know ?

Problems with triggering ?

{bestp}
Triggering checklist / best practices

url


Good forum : [url]


Valid HTML 4.01!   Valid CSS!

Updated 20131223  
go top