2

We have an application in which we are using JMS Queue and an MDB. I want that only one message should be sent to the MDB from the Queue at a time. I mean as soon as the MDB gets a message from the Queue, it should suspend the Queue and once the processing is finished, the Queue should be resumed. Can I write code for this in my MDB or is there any configuration I can make in ejb-jar.xml?

1
  • 2
    You might be able to adjust the pool to size 1 and only have 1 bean do the work.
    – tjg184
    Nov 14, 2012 at 13:23

2 Answers 2

2

I had to do the same with GlassFish once. You can tell your application server to create on consumer per MDB and then your MDB will be processing one message at a time. To do that in glassfish:

Open GlassFish Server Administration Console, navigate to the Configuration -> configuration-name -> EJB Container node and then select the MDB Settings tab.

Specify:

Maximum Pool Size: 1

And thats it for the glassfish. Restart server and you are good to go. Check this and this for more information.

0

Implement your MDB as:

@MessageDriven(name = "SingleThreadedMdb ", activationConfig = {
   @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
   @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/myQueue"),
   @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
   @ActivationConfigProperty(propertyName = "maxSession", propertyValue = "1"),
   @ActivationConfigProperty(propertyName = "consumerWindowSize", propertyValue = "0")
})
public class SingleThreadedMdb implements MessageListener {

  @Override
  public void onMessage(Message message) {
  }

}

Configure the queue in standalone-full.xml as:

<address-setting match="jms.queue.myQueue">
  <dead-letter-address>jms.queue.DLQ</dead-letter-address>
  <expiry-address>jms.queue.ExpiryQueue</expiry-address>
  <redelivery-delay>0</redelivery-delay>
  <max-delivery-attempts>1</max-delivery-attempts>
  <max-size-bytes>10485760</max-size-bytes>
  <address-full-policy>BLOCK</address-full-policy>
  <message-counter-history-day-limit>10</message-counter-history-day-limit>
</address-setting>

Under jms destinations add:

<jms-queue name="myQueue">
  <entry name="/queue/myQueue"/>
  <durable>true</durable>
</jms-queue>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.