Enrique San Martín Enrique San Martín - 1 year ago 136
Java Question

ActiveMQ throttling consumer

i want to do a throttling to a consumer of some queue in the activeMQ, in hornetq (of jboss, this is do it with annotations on the definition of the mdb Consumer). I can't find any similar in the documentation of activemq, the closest that i find was this

consumer.recvDelay 0 ms Pause consumer for recvDelay milliseconds with each message (allows consumer throttling).

from: http://activemq.apache.org/activemq-performance-module-users-manual.html

But there i can't find how i can do it in java.

Thanks in advance,


EDIT: Here is the ActiveMQManager code and the consumer code:

public class ActiveMQManager {

private static ActiveMQConnectionFactory CONNECTION_FACTORY;

public static Connection CONNECTION;

public static Session SESSION;

public static Destination TEST_QUEUE;

public static void start() {
try {

CONNECTION_FACTORY = new ActiveMQConnectionFactory("vm://localhost");


SESSION = CONNECTION.createSession(false,

TestClient testClient = new TestClient();


MessageConsumer testConsumer = SESSION.createConsumer(TEST_QUEUE);

} catch (Exception e) {

public static void stop() {
try {
// Clean up
} catch (JMSException e) {


The consumer code is very simple (for this example):

public class TestConsumer implements MessageListener {

public void onMessage(Message message) {
//Do something with the message



this depends on the consumer technology being used...but here are a few options

  • you can manually introduce a delay in your consumer code (not an exact science but this will limit the throughput)

  • you can also control the number of threads that your consumer uses by setting maxConcurrentConsumers property of you JMS connection...that said, this won't throttle message throughput, just limit the level of concurrency being used by your consumer

  • better yet, you can set the exact number of messages to consume per time period using a throttler EIP implementation

    for example, this is trivial using the Camel Throttler