File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes how to slow down JMS Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "how to slow down JMS" Watch "how to slow down JMS" New topic

how to slow down JMS

Rikko Verrijzer
Ranch Hand

Joined: Jul 22, 2003
Posts: 34
I'm building an application which gets its requests from a JMS queue.
The problem I'm currently facing is that the JMS calls the onMessage() method faster than the application can handle the requests. Therefore I'm looking for a way to slow down the rate of the onMessage()calls. Preferably without slowing JMS in general, since this application is not the only application connecting to the JMS.
Hope that anyone has some usefull hint for this problem.
Thanks in advance
PS. slowing down the message supplier is not an option.
Rama Yanegalla

Joined: Feb 02, 2004
Posts: 2
You can slow down by cutting number in the pool ( at setup time for the Listner Port) or by using transactions.
Lasse Koskela

Joined: Jan 23, 2002
Posts: 11962
I see two other options:
1) Use a separate scheduler queue to trigger your MDB, and let the MDB read messages from the original queue using raw JMS. This approach let's you control the rate of message consumption more flexibly.
2) Have the MDB sleep for a while before consuming the next message. I.e. use Thread#sleep(long) before returning from the onMessage() method). This is actually forbidden by the specification, but should work regardless.

Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Melody Siu

Joined: Nov 06, 2003
Posts: 21
Don't use MDB but write your own class to read out from queue and process.
Schedule this process to run periodically.
I agree. Here's the link:
subject: how to slow down JMS
It's not a secret anymore!