Manage objects for triggering
IBM MQ enables you to start an application automatically when certain conditions on a queue are met. For example, you might want to start an application when the number of messages on a queue reaches a specified number. This facility is called triggering. We have to define the objects that support triggering.
Triggering described in detail in Starting IBM MQ applications using triggers.
Defining an application queue for triggering
An application queue is a local queue that is used by applications for messaging, through the MQI. Triggering requires a number of queue attributes to be defined on the application queue.
Triggering itself is enabled by the Trigger attribute (TRIGGER in MQSC commands). In this example, a trigger event is to be generated when there are 100 messages of priority 5 or greater on the local queue MOTOR.INSURANCE.QUEUE, as follows:DEFINE QLOCAL (MOTOR.INSURANCE.QUEUE) + PROCESS (MOTOR.INSURANCE.QUOTE.PROCESS) + MAXMSGL (2000) + DEFPSIST (YES) + INITQ (MOTOR.INS.INIT.QUEUE) + TRIGGER + TRIGTYPE (DEPTH) + TRIGDPTH (100)+ TRIGMPRI (5)where:
- QLOCAL (MOTOR.INSURANCE.QUEUE)
- Is the name of the application queue being defined.
- PROCESS (MOTOR.INSURANCE.QUOTE.PROCESS)
- Is the name of the process definition that defines the application to be started by a trigger monitor program.
- MAXMSGL (2000)
- Is the maximum length of messages on the queue.
- DEFPSIST (YES)
- Specifies that messages on this queue are persistent by default.
- INITQ (MOTOR.INS.INIT.QUEUE)
- Is the name of the initiation queue on which the queue manager is to put the trigger message.
- TRIGGER
- Is the trigger attribute value.
- TRIGTYPE (DEPTH)
- Specifies that a trigger event is generated when the number of messages of the required priority (TRIGMPRI) reaches the number specified in TRIGDPTH.
- TRIGDPTH (100)
- Is the number of messages required to generate a trigger event.
- TRIGMPRI (5)
- Is the priority of messages that are to be counted by the queue manager in deciding whether to generate a trigger event. Only messages with priority 5 or higher are counted.
Defining an initiation queue
When a trigger event occurs, the queue manager puts a trigger message on the initiation queue specified in the application queue definition. Initiation queues have no special settings, but we can use the following definition of the local queue MOTOR.INS.INIT.QUEUE for guidance:DEFINE QLOCAL(MOTOR.INS.INIT.QUEUE) + GET (ENABLED) + NOSHARE + NOTRIGGER + MAXMSGL (2000) + MAXDEPTH (1000)
Defining a process
Use the DEFINE PROCESS command to create a process definition. A process definition defines the application to be used to process messages from the application queue. The application queue definition names the process to be used and thereby associates the application queue with the application to be used to process its messages. This is done through the PROCESS attribute on the application queue MOTOR.INSURANCE.QUEUE. The following MQSC command defines the required process, MOTOR.INSURANCE.QUOTE.PROCESS, identified in this example:DEFINE PROCESS (MOTOR.INSURANCE.QUOTE.PROCESS) + DESCR ('Insurance request message processing') + APPLTYPE (UNIX) + APPLICID ('/u/admin/test/IRMP01') + USERDATA ('open, close, 235')Where:
- MOTOR.INSURANCE.QUOTE.PROCESS
- Is the name of the process definition.
- DESCR ('Insurance request message processing')
- Describes the application program to which this definition relates. This text is displayed when we use the DISPLAY PROCESS command. This can help you to identify what the process does. If we use spaces in the string, we must enclose the string in single quotation marks.
- APPLTYPE (UNIX)
- Is the type of application to be started.
- APPLICID ('/u/admin/test/IRMP01')
- Is the name of the application executable file, specified as a fully qualified file name. In Windows systems, a typical APPLICID value would be c:\appl\test\irmp01.exe.
- USERDATA ('open, close, 235')
- Is user-defined data, which can be used by the application.
Display attributes of a process definition
Use the DISPLAY PROCESS command to examine the results of our definition. For example:DISPLAY PROCESS (MOTOR.INSURANCE.QUOTE.PROCESS) 24 : DISPLAY PROCESS (MOTOR.INSURANCE.QUOTE.PROCESS) ALL AMQ8407: Display Process details. DESCR ('Insurance request message processing') APPLICID ('/u/admin/test/IRMP01') USERDATA (open, close, 235) PROCESS (MOTOR.INSURANCE.QUOTE.PROCESS) APPLTYPE (UNIX)We can also use the MQSC command ALTER PROCESS to alter an existing process definition, and the DELETE PROCESS command to delete a process definition.
Parent topic: Work with local IBM MQ objects