Link to home
Start Free TrialLog in
Avatar of texastemplar
texastemplar

asked on

Throttling JMS Ques in Spring

I am developing an app that uses JMS ques in Spring. The app runs on a JBoss server. The ques are asynchronous and I am placing several messages on the que. The problem is I only want to process a couple of messages at a time. Does anyone know how I can set the que/listener so that only a few messages get sent to the listener, those messages get processed, then another couple of messages get sent to the listener and so on until Im out of messages?
ASKER CERTIFIED SOLUTION
Avatar of manuel_m
manuel_m
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of texastemplar
texastemplar

ASKER

Im trying to slow down the queue so it doesnt send all of the messages to the receivers at once. Possibly a pause between each message or have the queue pass a certain number of messages, then pause, then pass more messages. Im also using Spring to interact with the queues. Can you throttle the queue using Spring? Im thinking that maybe there is a parameter I can place in the spring.xml config file to limit the speed that the queue passes messages. Perhaps there is some spring code I can use to slow things down?
The only thing I can point to are these websites. There is a configuration example in "19.6 JMS Namespace Support" before "Table 19.3. Attributes of the JMS <jca-listener-container/> element" where you can set a prefetch parameter. With this parameter the consumer prefetches the given number of messages and waits for acknowlege (if a TransactionManager is set).

http://static.springframework.org/spring/docs/2.5.x/reference/jms.html#jms-jca-message-endpoint-manager
http://static.springframework.org/spring/docs/2.5.x/reference/jms.html#jms-namespace

I hope this helps. Otherwise I see no possibility to slow things down with spring.

manuel
I solved my problem. There is a parameter you can set in the messagelistener container defined in the spring xml file called concurrentConsumers. This limits the number of consumers. Then in each consumer use thread.sleep to slow its consumption of messages.