R – How to pause JMS topic subscriber from receiving messages

jbossjmsmessagingsubscriber

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?

Best Answer

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.

Related Topic