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

2

15

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

Joaquinajoash answered 11/2, 2011 at 20:11 Comment(5)
Which version of JBoss? What does your MDB config look like?Purdah
@Purdah : The Jboss version is : [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? ThanksJoaquinajoash
Add the info to the question, it's not readable when posted as a comment.Purdah
@skaffman: Sorry! I'll do that right now.Joaquinajoash
See also #7331887Lawannalawbreaker
A
16

Try an additional acitivation config property:

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

where someNumber is the maximum number of instances you want.

Aminaamine answered 25/2, 2011 at 21:46 Comment(4)
I think it should be maxSessions instead of maxSession. I have tried both with value of 1 and its sending more than one at the same time.Battaglia
@LoJuego All the supported activation config properties are listed in this tutorial: docs.jboss.org/ejb3/docs/tutorial/mdb/mdb.html. maxSession is the correct property name.Aminaamine
Can I apply similar property on WebLogic?Voorhis
I would guess WebLogic provides something similar but I doubt the property name is the same. maxSession is a JBoss extension to the JCA specification properties.Aminaamine
A
1

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).

Antidepressant answered 5/3, 2011 at 10:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.