1

In Websphere MQ I can configure a Queue to Trigger an Application when a message arrives.
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?

I tried ActiveMQ but it hasn't triggers.

Thomas8
  • 1,117
  • 1
  • 11
  • 22
  • Suggest you tag your question so experts in other JMS providers see it, as you've only tagged it for websphere-MQ and you already know the answer for that one :-) – Morag Hughson Apr 28 '15 at 23:20
  • @MoragHughson Thanks, I added those that exist.. – Thomas8 Apr 29 '15 at 06:12
  • Doesn't websphere MQ just send a new message to a trigger queue when there is a message in the main queue? How is that different from starting your real application thread from the onMessage method of a "trigger" thread? onMessage is part of JMS, so all the JMS clients implement it. You could even have a trigger client generate a new trigger message in a new queue if that is absolutely necessary. – RaGe Apr 30 '15 at 05:17
  • @RaGe yes, it's seems acceptable. Could you try to explain in an answer? maybe with some reference? When arrives a message and myApplication is still in execution, WMQ doen't launch it again, it's supposed that the user application consume all messagges in the queue.Can I expect similar behavior? Or all messages call "onMessage"? – Thomas8 Apr 30 '15 at 06:08

1 Answers1

1

qpid does not have a websphere-MQ like monitor trigger feature. I know ActiveMQ doesn't either, and I suspect this may be true of other JMS providers as well. 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:

JMS spec defines an asynchronous delivery mode. See section 4.5.2. So you should be able to do this with any JMS provider. An asynchronous listener implements the javax.jms.MessageListener interface. 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.

Suppose the main application queue is mainQ. You create a new MessageListener for mainQ, in browse mode - so as to not actually consume any messages from 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.

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

Community
  • 1
  • 1
RaGe
  • 22,696
  • 11
  • 72
  • 104