views:

1001

answers:

3

My setup: JBoss Messaging 1.4 running on JBoss 4.2.3

I have a couple of MDB's that subscribes on one topic, and the MDB's onMessage() tries to deliver the received message to one web service each.

My problem is that I can't figure out how to pause the subscriptions in the case when the web service is offline.

My plan is to do the following in onMessage():

  1. try to deliver to web service
  2. if offline:
  3. --> pause the subscription
  4. --> throw exception in onMessage() to make JMS redeliver the message until the web service goes online again
  5. --> start the subscription

I want to pause ONLY the one subscription that have the problem - NOT all my subscribers.

Any suggestion on how to solve this?

A: 

Why do you want to pause the subscription? Just throw an exception and go to sleep for, say, 30 seconds. The exception will roll back the JMS transaction and put the message back into the queue.

The sleep makes sure that this doesn't become a DoS attack while the web service is offline (by delivering and rolling back the message many times per second).

[EDIT] If you have many listeners for the same topic (for performance reasons), I suggest to create an independent process which listens for "Web service down" messages and unsubscribes all the normal listeners in this case.

The process should then wait until the service is available again and re-subscribe the listeners.

Aaron Digulla
Your suggestion seems like a good idea! I have now tried it, but I have some problems with it:Incoming message are processed in parallel. This results in having many messages in sleep.Also, the max redelivery count will hit the limit at some point and are then put on DLQ, even if the host hasn't gone online yet. Therefor, it would be nice to just pause the listener from consuming new messages until the host is online again.Is it a better solution to setup my topic listeners programatically, and process my incoming messages this way? Then I guess it's mush easier to pause/stop it...?
Rickard
See my edits. Yes, if you have many listeners, you need a way to stop them all. In this case, managing the subscriptions with an additional process is your best option.
Aaron Digulla
A: 

Can't you stop the listener who listens to any incoming messages in the topic?

Here is the link for the doc of Listener, and it has a pause method. You can follow the same approach, and detail can be found in their distribution. http://synapse.apache.org/apidocs/org/apache/synapse/transport/jms/JMSListener.html

Another one to show you how to stop your consumer: http://livedocs.adobe.com/blazeds/1/javadoc/flex/messaging/services/messaging/adapters/JMSConsumer.html#stop()

They are all basically the same.

paradisonoir
That would be nice, but I can't figure out how to do this in my MDB. If I setup a topic listener programatically I guess it's easy, but my solution consist of simple MDB's with just the onMessage(). Any tip how to make a stop() from it?
Rickard
I edited my answer. Does that help?
paradisonoir
A: 

This is very similar to the scenario in http://stackoverflow.com/questions/625725/how-to-temporarily-disable-a-message-listener/628337#628337

Only difference is you're an MDB rather than a plain Java client. Could you just avoid returning from onMessage() until your web service is working again? You'd have to arrange your onMessage() logic to block or sleep. Sleeping is a technical violation of the EJB spec, but depending on what you're considering as an alternative, it may be no uglier.

John M