+

Search Tips | Advanced Search

Starting IBM MQ applications using triggers

Learn about triggers and how to start IBM MQ applications using triggers.

Some IBM MQ applications that serve queues run continuously, so they are always available to retrieve messages that arrive on the queues. However, you might not want this when the number of messages arriving on the queues is unpredictable. In this case, applications could be consuming system resources even when there are no messages to retrieve.

IBM MQ provides a facility that enables an application to be started automatically when there are messages available to retrieve. This facility is known as triggering.

For information about triggering channels see Triggering channels.


What is triggering?

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 reduces logging (resulting in improving performance), and minimizing duplicates during restart, so improving restart time.

The program that 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. Typically this action is to start some other application to process the queue that generated the trigger message. 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, we can create a process-definition object associated with it. This object contains information about the application that processes the message that 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.

To trigger the start of a channel, we do not need to define a process definition object. The transmission queue definition is used instead.

Triggering is supported by IBM MQ clients running on UNIX, Linux, and Windows. An application running in a client environment is the same as one running in a full IBM MQ environment, except that you link it with the client libraries. However the trigger monitor and the application to be started must both be in the same environment.

Triggering involves:

    Application queue
    An application queue is a local queue that, when it has triggering set on and when the conditions are met, requires that trigger messages are written.

    Process definition
    An application queue can have a process definition object associated with it that holds details of the application that will get messages from the application queue. (See Attributes for process definitions for a list of attributes.)
    Remember that if we want a trigger to start a channel, we do not need to define a process definition object.

    Transmission queue
    You need a transmission queue if we want a trigger to start a channel.
    For a transmission queue on any platform other than Linux, the TriggerData attribute of the transmission queue can specify the name of the channel to be started. This can replace the process definition for triggering channels, but is used only when a process definition is not created.

    Trigger event
    A trigger event is an event that causes a trigger message to be generated by the queue manager. This is typically a message arriving on an application queue, but it can also occur at other times. For example, see Conditions for a trigger event.
    IBM MQ has a range of options to allow you to control the conditions that cause a trigger event (see Control trigger events ).

    Trigger message
    The queue manager creates a trigger message when it recognizes a trigger event. It copies into the trigger message information about the application to be started. This information comes from the application queue and the process definition object associated with the application queue.
    Trigger messages have a fixed format (see Format of trigger messages ).

    Initiation queue
    An initiation queue is a local queue on which the queue manager puts trigger messages. Note that an initiation queue cannot be an alias queue or a model queue.
    A queue manager can own more than one initiation queue, and each one is associated with one or more application queues.
    A shared queue, a local queue accessible by queue managers in a queue sharing group, can be an initiation queue on IBM MQ for z/OS .

    Trigger monitor
    A trigger monitor is a continuously running program that serves one or more initiation queues. When a trigger message arrives on an initiation queue, the trigger monitor retrieves the message. The trigger monitor uses the information in the trigger message. It issues a command to start the application that is to retrieve the messages arriving on the application queue, passing it information contained in the trigger message header, which includes the name of the application queue.
    On all platforms, a special trigger monitor known as the channel initiator is responsible for starting channels.
    On z/OS, the channel initiator is typically started manually, or it can be done automatically when a queue manager starts by changing CSQINP2 in the queue manager startup JCL.
    On Multiplatforms, the channel initiator is started automatically when the queue manager starts, or it can be started manually with the runmqchi command.
    For more information, see Trigger monitors.

To understand how triggering works, consider Figure 1, which is an example of trigger type FIRST (MQTT_FIRST).

Figure 1. Flow of application and trigger messages
In Figure 1, the sequence of events is:
  1. Application A, which can be either local or remote to the queue manager, puts a message on the application queue. 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.

Note:

  1. If the application queue is open for input, by any program, and has triggering set for FIRST or DEPTH, no trigger event occurs because the queue is already being served.
  2. If the initiation queue is not open for input, the queue manager does not generate any trigger messages; it waits until an application opens the initiation queue for input.
  3. When using triggering for channels, use trigger type FIRST or DEPTH.
  4. Triggered applications run under the user ID and group of the user who started the trigger monitor, the CICS user, or the user who started the queue manager.

So far, the relationship between the queues within triggering has been only on a one to one basis. Consider Figure 2.

Figure 2. Relationship of queues within triggering

An application queue has a process definition object associated with it that holds details of the application that will process the message. The queue manager places the information in the trigger message, so only one initiation queue is necessary. The trigger monitor extracts this information from the trigger message and starts the relevant application to deal with the message on each application queue.

Remember that, if we want to trigger the start of a channel, we do not need to define a process definition object. The transmission queue definition can determine the channel to be triggered.

Use the following links to find out more about starting IBM MQ applications using triggers:

  • Prerequisites for triggering
    Use this information to learn about the steps to take before using triggering.
  • Conditions for a trigger event
    The queue manager creates a trigger message when the conditions detailed in this topic are satisfied.
  • Control trigger events
    You control trigger events using some of the attributes that define the application queue. This information also gives examples of using the trigger types: EVERY, FIRST, and DEPTH.
  • Designing an application that uses triggered queues
    We have seen how to set up, and control, triggering for the applications. Here are some tips to consider when you design the application.
  • Trigger monitors
    To a queue manager, a trigger monitor is like any other application that serves a queue. However, a trigger monitor serves initiation queues.
  • Properties of trigger messages
    The following topics describe some other properties of trigger messages.
  • When triggering does not work
    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; otherwise, the trigger monitor cannot start the program.

Parent topic: Writing a procedural application for queuing


Related concepts

Last updated: 2020-10-04