简体   繁体   English

像MQ系列一样在JMS Provider中触发监视器

[英]Trigger Monitor in JMS Provider like MQ Series

In Websphere MQ I can configure a Queue to Trigger an Application when a message arrives. 在Websphere MQ中,我可以配置队列以在消息到达时触发应用程序。
In that way I can have an Application that starts only if needs and I don't have to manage one daemon that wait for message in that queue. 这样,我可以拥有一个仅在需要时启动的应用程序,而不必管理一个等待该队列中消息的守护程序。
More information about here 有关此处的更多信息

Are There an open source JMS Provider that bring this functionality? 是否有提供此功能的开源JMS提供程序?

I tried ActiveMQ but it hasn't triggers. 我尝试过ActiveMQ,但没有触发。

qpid does not have a websphere-MQ like monitor trigger feature. qpid没有像监视器触发触发功能那样的websphere-MQ。 I know ActiveMQ doesn't either, and I suspect this may be true of other JMS providers as well. 我知道ActiveMQ也不是,我怀疑其他JMS提供程序也可能如此。 However, it is possible to roll out your own monitor-trigger. 但是,有可能推出您自己的监视器触发。

A homebrew monitor-trigger would then become an application process(albeit light-lightweight) that you will have to manage though, would you be better off managing an actual application thread itself? 自制监视器触发将成为您必须管理的应用程序进程(尽管轻巧),您会更好地管理实际的应用程序线程本身吗?


To implement a monitor trigger in qpid: 要在qpid中实现监视器触发器:

JMS spec defines an asynchronous delivery mode. JMS规范定义了异步交付模式。 See section 4.5.2 . 参见第4.5.2节 So you should be able to do this with any JMS provider. 因此,您应该可以使用任何JMS提供程序来执行此操作。 An asynchronous listener implements the javax.jms.MessageListener interface. 异步侦听器实现javax.jms.MessageListener接口。 The method onMessage() needs to be implemented and serves as the callback function when any new message appears on the queue it is subscribed to. 方法onMessage()需要实现,并在订阅的队列上出现任何新消息时用作回调函数。

Suppose the main application queue is mainQ . 假设主应用程序队列是mainQ You create a new MessageListener for mainQ , in browse mode - so as to not actually consume any messages from mainQ 您可以在浏览模式下为mainQ创建一个新的MessageListener ,以便实际上不消耗mainQ的任何消息。

Destination mainQ = (Destination) session.createQueue("mainQ; {mode: browse}");
MessageConsumer mainQConsumer = session.createConsumer(mainQ);
mainQConsumer.setMessageListener(this);

In the onMessage() function you can either create a new message in a separate triggerQ or you can skip this step and get right to starting up the application. onMessage()函数中,您可以在单独的triggerQ创建新消息,也可以跳过此步骤而直接启动应用程序。

public void onMessage(Message message)
{
  TextMessage triggerMessage = session.createTextMessage("Trigger-start-Application-X");

  Destination triggerQ = (Destination) session.createQueue("triggerQ");
  triggerQProducer = session.createProducer(triggerQ);
  this.triggerQProducer.send(triggerMessage);

  // Or alternatively:
  // if (!applicationIsActive()) activateApplication()
}

See full working sample here: https://github.com/foragerr/qpid-trigger-demo 在此处查看完整的工作示例: https : //github.com/foragerr/qpid-trigger-demo

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM