IBM Websphere MQ 基础5:触发器trigger

概念

    A trigger monitor is an application that processes the trigger messages that are put on initiation queues when a trigger event occurs.

      触发监控器是一个进程,用于当触发事件发生时处理被put进initiation队列的触发消息;

    If triggering is enabled for a queue and a trigger event occurs, the queue manager sends a trigger message to the initiation queue. The trigger monitor reads the trigger message and takes appropriate action, based on the data in the trigger message. Normally, this action would be to start some other application to process the queue that caused the trigger message to be generated. From the point of view of the queue manager, there is nothing special about a trigger monitor; it is just another application that reads messages from a queue (the initiation queue).

   如果一个队列的触发功能被使能且触发事件产生,QM会发送一个触发消息至initiation队列。基于触发消息中的数据,触发监控器读触发消息并执行相关动作。一般情况下,此动作是启动一些应用去处理产生此触发消息的队列。从QM的角度看,触发监控器没有特别之处,其仅仅是从另外一个队列中读取消息。

      When you have started a trigger monitor, it just continues monitoring the specified initiation queue. You cannot stop a trigger monitor directly. When you stop the trigger monitor's queue manager, the trigger monitor stops too.

         当你启动一个触发监控器,其仅仅是监控特定的initiation队列。你可以直接停止触发监控器。但你停止触发监控其的QM,触发监控器随之停止。

触发类型

first:当第一个消息到来是触发;

every:每次消息到来是均会触发;

depth:基于queue深度的触发;

配置事例

         为了更加深入理解trigger的使用,在一个远程队列架构的发送端传输队列中配置了一个基于深度的trigger,触发深度为5。如图:                             

         触发数据:DATA为发送端的传输通道sdr_channel,initiation queue为系统默认队列。当触发事件发生时,QM会发送一个触发消息至initiation队列,触发进程读取initiation queue并执行触发事件(本例是启动发送通道);

      起初,发送通道处于inactive状态:

 

      待向远程队列put 5条message后,sdr_channel被自动触发并发送远端QM的队列,而前四条message一致hold在传输队列中。直到第五条message到达,sdr_channel被触发,消息被发送至远端QM的队列。

 

扩展思考

  1. 触发可以用于触发某个通道,还可以用于触发某个进程process,有关IBM MQ中PROCESS资源的定义,将于后续分享;
  2. 触发可用于什么场景呢?笔者认为至少可用于:

a. 流量监控与反压。如基于depth的触发,但队列深度达到某个阈值,触发某个进程对消息生产者进行反压,要求其降低发送速率;

b. 负载不均衡时的休眠。如基于first的触发,在消息还没到达之前,可以设置处理进程为休眠,当消息到达时再进行触发处理。

猜你喜欢

转载自blog.csdn.net/zhaogang1993/article/details/90740128