Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to limit the number of MDB instances listening to a Jboss JMS queue

I'm having a problem with the following setup:

A Java application send email msg to a JMS queue, then an MDB listening to the queue get the email msg with the onMessage method, it open a connection on the Gmail SMTP, send the email to the SMTP and close the connection. Doing this on all message in the JMS queue.

It is working great when I have up to 5 messages in the queue at the same time. All messages are picked-up in the same time by 5 different instances of the MDB, so I have 5 concurrent connection to the Gmail SMTP server. But when there is more messages in the JMS queue, I get a connection error from the Gmail SMTP server. The 5 first messages are sent correctly, but not the rest of the bunch, so the other messages are lost because they are not in the queue anymore.

So my question is, is it possible to limit the number of MDB instance that will listen to the JMS queue? If I have a maximum of 5 MDB, then even if I have 1000 messages in the queue, it will just take longer to empty the queue, but at least I wont lose any message.

Any other suggestion to resolve this issue would be very much appreciated.

Here is the Jboss version:

[Server] Release ID: JBoss [Trinity] 4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)

and the config of the MDB is as following :

@MessageDriven(activationConfig = {   
  @ActivationConfigProperty( propertyName = "destinationType", propertyValue = "javax.jms.Queue" ),   
  @ActivationConfigProperty( propertyName = "destination", propertyValue = "queue/emailQueue")  
})

Do you need more?

Thanks

EDIT 2011-02-14
Maybe I'm all wrong wanting to limit the number of MDB instance. I saw a config about the number of JMS threads. If I limit the number of thread that will post to the MDB, maybe it will resolve my issue? Will the JMS wait until a MDB is available before posting msg again? Is there any side effect to do that? Your though please. Thanks
END EDIT

like image 747
Alain Avatar asked Feb 11 '11 20:02

Alain


People also ask

What is MDB in JMS?

A message-driven bean (MDB) is a consumer of messages from a Java™ Message Service (JMS) provider. An MDB is invoked on arrival of a message at the destination or endpoint that the MDB services. MDB instances are anonymous, and therefore, all instances are equivalent when not actively servicing a client message.

What happens when JMS queue is full?

When the queue fills, nothing can put new messages to it. In WebSphere MQ the producing application then receives a return code indicating that the queue is full. If the application distinguishes between fatal and transient errors, it can stop and retry.

What is JMS queue in Jboss?

Message Service Application Programming Interface, and it is used by applications to send asynchronous "business quality" messages to other applications. In the JMS world, messages are not sent directly to other applications. Instead, messages are sent to destinations, also known as "queues" or "topics".


2 Answers

Try an additional acitivation config property:

@ActivationConfigProperty( propertyName = "maxSession", propertyValue = "someNumber")

where someNumber is the maximum number of instances you want.

like image 190
Brent Worden Avatar answered Sep 21 '22 09:09

Brent Worden


If JBoss 4 has an option to limit the instances of a stateless session bean, one option could be to move the message processing code to this bean, and pass the incoming JMS messages to it. (IIRC any failures in the bean would also cause the JMS message to be unacknowledged so it would retry automatically).

like image 26
mjn Avatar answered Sep 19 '22 09:09

mjn