2

Question

Is it possible to stop a Message Driven Bean (programmatically), so that it doesn't consume new messages, but processes running transactions as usual?

(This is a follow up of How to stop message processing before undeploying?).

Given

  • JBoss 4.2.3 with JBoss Messaging
  • a Message Driven Bean according to EJB 2.0

Failed Attempts

  • I'd like to use the MBean method stopDelivery, but sadly it closes transactions immediately (see bug #EJBTHREE-1870) and thereby causes a lot of exceptions.
  • I tried to reduce the max pool size to 0 in the JMX console, but the number of active sessions isn't affected at all.
  • I could stop the queue, but than I have to handle NameNotFoundExceptions within the producers.
Community
  • 1
  • 1
Christian Strempfer
  • 7,291
  • 6
  • 50
  • 75

1 Answers1

1

Well here is a though, almost everything can be achieved with a wrapper, You can let MDB keep receive message, but introduce a Boolean stopDelivery, while before message going to be processed by business logic, check if stopDelivery is set to true, if so, resend the message back to your queue where it is came from.

So even the queue is still moving, but unless u unset stopDelivery, the content of the queue is kind of freeze

Ben.Yan
  • 118
  • 4
  • 13
  • But the wrapper MDB still consumes messages. A message could be lost, when the application is undeployed, before the message was resent to the queue. – Christian Strempfer Sep 19 '12 at 06:43
  • 1
    It seems the MDB is not fit for this occasion, then you will have to go 1 level deeper, i suggest you take a look at java JMS code, you can create a message consumer, it do support both receive and peek method, so you can decide when to receive a message and consume it from queue or not – Ben.Yan Sep 20 '12 at 09:57
  • http://docs.oracle.com/javaee/1.3/jms/tutorial/1_3_1-fcs/doc/jms_tutorialTOC.html – Ben.Yan Sep 20 '12 at 09:59