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?

Valentino Ru
  • 4,964
  • 12
  • 43
  • 78
user1818397
  • 79
  • 1
  • 2
  • 8

2 Answers2

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.

Community
  • 1
  • 1
Paulius Matulionis
  • 23,085
  • 22
  • 103
  • 143
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>
Boris Pavlović
  • 63,078
  • 28
  • 122
  • 148