概念
A process definition contains information about the application that starts in response to a trigger event on a queue manager. When you enable triggering on a queue, you can create a process definition and associate it with the queue. Each queue can specify a different process definition, or several queues can share the same process definition. If you create a process definition, the queue manager extracts the information from the process definition and places it in the trigger message for the trigger monitor to use.
IBM MQ中process definition包含应用程序的必要信息用于响应QM上的触发事件。当在queue上使能触发后,可以创建一个 process definition用于关联触发事件。每个队列可以指定不同的process definition,几个不同的queue也可以共享相关的process。创建process definition后,QM从process definition中抽取信息并放置于触发消息中以便触发监控器使用。
If you want to trigger the start of a channel, instead of an application, you do not need to create a process definition because the transmission queue definition is used instead.
若需求是触发channel的启动,则不需要创建process definition。
定义一个进程触发
- 创建启动进入队列管理器QmgrName
crtmqm QmgrName
strmqm QmgrName
runmqsc QmgrName
- 创建一个本地队列并启动触发监控
DEFINE QLOCAL('TRIGGER.QUEUE') REPLACE DESCR('Application queue to test triggering') SHARE TRIGGER TRIGTYPE (EVERY) INITQ('TEST.INIT.QUEUE') PROCESS('IBMMQ.PROCESS')
此触发监控的initiation queue为:TEST.INIT.QUEUE;
process define 为:IBMMQ.PROCESS;
触发类型为:every,每次都触发
- 定义一个process
DEFINE PROCESS('IBMMQ.PROCESS') REPLACE DESCR('Process to test triggering') APPLICID('/var/mqm/test_process.sh')
应用程序为一个脚本,脚本用于返回当前的脚本名$0:
[mqm@t24app1sg ~]<20190602 11:14:20>$ cat test_process.sh
#!/bin/bash
echo "This is process:" $0
- 定义initiation queue
DEFINE QLOCAL('TEST.INIT.QUEUE') REPLACE DESCR('Initiation queue to test triggering')
- 启动触发监控(linux视图,而不是runmqsc视图)
runmqtrm -m QmgrName -q TEST.INIT.QUEUE
启动后,触发监控进程循环监控initiation queue。
- 向TRIGGER.QUEUE中放置一条消息(另外开一个窗口,发送消息)
amqsput TRIGGER.QUEUE QmgrName
测试效果:
如此,结果表明:测试正确。
实际应用可根据应用场景对tigger type和process做很多文章。如基于深入depth的触发,当queue的深度达到达到阈值时,启动进程通知消息生产者暂缓消息发送。