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

5
  • Which version of JBoss? What does your MDB config look like?
    – skaffman
    Feb 12, 2011 at 12:49
  • @skaffman : 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? Thanks
    – Alain
    Feb 12, 2011 at 20:47
  • Add the info to the question, it's not readable when posted as a comment.
    – skaffman
    Feb 12, 2011 at 20:55
  • @skaffman: Sorry! I'll do that right now.
    – Alain
    Feb 12, 2011 at 21:01
  • See also stackoverflow.com/questions/7331387/…
    – Vadzim
    Sep 25, 2012 at 6:00

2 Answers 2

16

Try an additional acitivation config property:

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

where someNumber is the maximum number of instances you want.

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.
    – Lo Juego
    Sep 21, 2012 at 12:07
  • 3
    @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. Sep 24, 2012 at 14:19
  • Can I apply similar property on WebLogic? Feb 19, 2016 at 2:16
  • 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. Feb 19, 2016 at 2:51
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).

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.