|
home /
infca /
mq / mq_trig
(navigation links)
|
God made everything out of nothing,
but the nothingness shows through
Paul Valery
|
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.
-
1. Application A, which can be either local or remote to the queue manager,
puts a message on the application queue.
Note that no application has this queue open for input.
However, this fact is relevant only to trigger type FIRST and DEPTH.
-
2. The queue manager checks to see if the conditions are met
under which it has to generate a trigger event.
They are, and a trigger event is generated.
Information held within the associated process definition object
is used when creating the trigger message.
-
3. The queue manager creates a trigger message
and puts it on the initiation queue associated with this application queue,
but only if an application (trigger monitor)
has the initiation queue open for input.
-
4. The trigger monitor retrieves the trigger message from the initiation queue.
-
5. The trigger monitor issues a command to start application B (the server application).
-
6. Application B opens the application queue and retrieves the message.
Prerequisites for triggering
MQ Application Programming Guide, SC34-6064-02, page 196.
Before your application can take advantage of triggering, follow the steps below:
-
1. Create an initiation queue for your application queue.
For example:
DEFINE QLOCAL (initiation.queue) REPLACE +
LIKE (SYSTEM.DEFAULT.LOCAL.QUEUE) +
DESCR ('initiation queue description')
-
2. Associate the initiation queue with the application queue.
A queue manager can own more than one initiation queue.
You may want some of your application queues to be served by different programs,
in which case you could use one initiation queue for each serving program,
although you do not have to.
Here is an example of how to create an application queue:
DEFINE QLOCAL (application.queue) REPLACE +
LIKE (SYSTEM.DEFAULT.LOCAL.QUEUE) +
DESCR ('appl queue description') +
INITQ ('initiation.queue') +
PROCESS ('process.name') +
TRIGGER +
TRIGTYPE (FIRST)
-
3. If you are triggering an application, create a process definition
object to contain information relating to the application
that is to serve your application queue.
For example, to trigger-start a CICS payroll transaction called PAYR:
DEFINE PROCESS (process.name) +
REPLACE +
DESCR ('process description') +
APPLTYPE ('CICS') +
APPLICID ('PAYR') +
USERDATA ('Payroll data')
When the queue manager creates a trigger message,
it copies information from the attributes of the process definition object
into the trigger message.
-
4. You need to create a process definition
if you want to trigger a channel and you are using a Version 2 MQSeries product.
Otherwise, you can create a transmission queue definition
and use blanks for the ProcessName attribute.
The TrigData attribute can contain the name of the channel to be triggered
or it can be left blank.
Except on WebSphere MQ for z/OS, if it is left blank,
the channel initiator searches the channel definition files
until it finds a channel that is associated with the named transmission queue.
When the queue manager creates a trigger message,
it copies information from the TrigData attribute
of the transmission queue definition into the trigger message.
-
5. If you have created a process definition object
to specify properties of the application that is to serve your application queue,
associate the process object with your application queue
by naming it in the ProcessName attribute of the queue.
-
6. Start instances of the trigger monitors
(or trigger servers in WebSphere MQ for iSeries)
that are to serve the initiation queues you have defined.
See "Trigger monitors" on page 206 for more information.
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
- Host = "T42" ;
- Qmgr = "Q3" ;
- DLQ = "Q3DLQ" ;
- Data Q = "Q3SAG" ;
Usage = "normal" ; (rx)
Trigger Control = 'on' / 'every' ;
Initiation Q = "Q3IQ" ;
Process Name = "PSAG" ;
- Init Q = "Q3IQ" ;
Usage = "normal" ; (rx)
- Process = "PSAG" ;
Process Definition Name = "PSAG" ;
Application Type = Windows ;
Application Identifier = "\\cpp\winpopup\uno.exe"
- MQ Services + "Create a New Trigger Monitor Service"
Parameters : "Queue Name := Q3IQ ;"
Si se omite el nombre, se utilizará SYSTEM.DEFAULT.INITIATION.QUEUE
-
MQ v7 : MQ Explorer + <qmn> + Advanced + Services + New Service
Service Name = "MyTrigger" ;
Service Control = QMgr ;
Start Command = "c:\MQ\bin\runmqtrm.exe" ;
Start Args = "-m QMM2 -q QL.QMM2.TIQ" ;
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
- Host = "T42" ;
- Qmgr = "Q2" ;
- Data Q = "QTRIG" ;
Usage = "normal" ; (rx)
Trigger Control = 'on' / 'every' ;
Initiation Q = "QINI" ;
Process Name = "SAGPROC" ;
- Init Q = "QINI" ;
- Process = "SAGPROC" ;
Application Type = Windows NT ;
Application Identifier = "\\cpp\timewr\wr2fi.exe" [sin START muestra los parámetros de entrada]
- Trigger Monitor : "start runmqtrm -m Q2 -q QINI" (A)
from c:\TEMP directory (B).
- Resultat : [at (A) window]
AMQ8618 Error starting triggered application.
Explanation: An error was detected when trying to start the application identified in a trigger message.
User Response: Check that the application the trigger
Se escribia un string largo en una variable de 128 bytes.
*** Fixed & OK ***
In (B) directory, a ZZZ.SAG is created, containing
(
TMC StrucId
2 Version
QTRIG QName
sagproc ProcessName
popoxo TriggerData
\\cpp\timewr\wr2fi.exe ApplId
1234 EnvData
ABCD UserData
Q2 Qmgr
)
My local time is [Wed Oct 12 11:09:14 2005].
The MQTM strucure is like this :
assemble with \\mq\tools\c\include\cmqc.h
link to \\mq\tools\lib\mqm.lib
struct tagMQTM {
MQCHAR4 StrucId ; /* Structure identifier */
MQLONG Version ; /* Structure version number */
MQCHAR48 QName ; /* Name of triggered queue */
MQCHAR48 ProcessName ; /* Name of process object */
MQCHAR64 TriggerData ; /* Trigger data */
MQLONG ApplType ; /* Application type */
MQCHAR256 ApplId ; /* Application identifier */
MQCHAR128 EnvData ; /* Environment data */
MQCHAR128 UserData ; /* User data */
} ;
\\MQ\Eines\TrigCode\mycode.c
Cliente : T42 VM("MB", ip=192.168.157.129 [HostNet], mq v 5.3)
Requerimientos :
- copiamos \\mq\eines\trigcode\mycode.exe (escribe en c:\SAG_TRIG.TRC)
- activamos "runmqtmc -m QM1 -q SAGINITQ"
Servidor : T42 VM("GNI", ip=192.168.157.128 [HostNet], mq v 6.0)
Requerimientos :
- usamos queue manager QM1
- definimos Process "CLITRI" como "\\mq\eines\trigcode\mycode.exe"
- definimos cola SAGDATQ como "trigger, "every" y usando "CLITRI" y SAGINITQ.
- definimos cola SAGINITQ
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 */
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
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:
- In the Navigator view, expand the queue manager on which you want to start the trigger monitor service.
- Right-click the queue manager's Services folder, then click New... > Service. The New Service dialog opens.
- In the New Service dialog, type a name for the service, for example, TriggerMonitor, then click Next.
You can now configure the new service.
- Optional: In the Service desc field, type a description of the service,
for example "A trigger monitor for queue manager QM1".
- 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.
- 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
- 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.
- 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.
- 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.
- Click Finish.
The new service is created on the selected queue manager.
To start the trigger monitor using the service that you previously created:
- In the Navigator view, click the Services folder to display the services on queue manager, in the Content view.
- 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 :
- 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" ;
- la cua de events de Trigger, aquí AAINITQ,
ha de ser senzillament de Recepció (Normal).
- 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" ;
- 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.
Problems with triggering ?
-
Try "disable and then reenable triggering on the xmitq" ...
-
Use
runmqtrm [-m NombGstCola] [-q ColaInic]
to see the problem details !
-
Always start the program in the background
by using an & suffix on the Unix platforms and the "start" prefix on Windows.
{bestp}
Triggering checklist / best practices
- triggering must be enabled, and of the correct type
- no application can already have the queue open to get messages
- the initiation queue must be valid
- a trigger monitor must be active against the initiation queue
- the process definition must be valid
- the trigger monitor must be able to start the application
- the application must connect to the queue after it is started
- if you are triggering a shell which runs a program, make sure the program has an absolute path, as the shell will run in an uncofig'd environment
url
Good forum :
[url]