Active ActiveMQ Member

I want to do throttling for a consumer of some queue in activeMQ, in hornetq (from jboss, this is done with annotations according to the definition of the mdb user). I can not find anything like this in the activemq documentation, the closest I found is

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 I can not find how I can do this in java.

Thanks in advance,

Sincerely.

EDIT: Here is the ActiveMQManager code and user 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"); CONNECTION = CONNECTION_FACTORY.createConnection(); CONNECTION.start(); SESSION = CONNECTION.createSession(false, Session.CLIENT_ACKNOWLEDGE); TestClient testClient = new TestClient(); TEST_QUEUE = SESSION.createQueue("TEST.QUEUE"); MessageConsumer testConsumer = SESSION.createConsumer(TEST_QUEUE); test.setMessageListener(testClient); } catch (Exception e) { } } public static void stop() { try { // Clean up SESSION.close(); CONNECTION.close(); } catch (JMSException e) { log.error(e); } } 

}

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

 public class TestConsumer implements MessageListener { @Override public void onMessage(Message message) { //Do something with the message } 

}

+4
source share
3 answers

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

  • you can manually enter a delay in your consumer code (not an exact science, but it will limit bandwidth)

  • you can also control the number of threads used by your consumer by setting the maxConcurrentConsumers property of your JMS connection ... however, this will not throttle the message throughput, just limit the level of concurrency usage by your consumer

  • even better, you can set the exact number of messages consumed over a period of time using the EIP throttle implementation

    for example, this is trivial using Camel Throttler

    from("activemq:queueA").throttle(10).to("activemq:queueB")

+7
source

With ActiveMQ, you can set the consumer preform limit: http://activemq.apache.org/what-is-the-prefetch-limit-for.html

To configure it, you can use the connection URL (most configurations can be done using the URL) or the Java API.

For more interesting options: http://activemq.apache.org/connection-configuration-uri.html

+3
source

Note that Camel Throttler supports exchanges in memory when they are blocked by Throttler. Thus, if you have 100 queue users and a server (exposing a SOAP service), you can have up to 100 exchanges in memory!

Submitted this question for this: Throttle consumption rate for all JMS users listening on ActiveMQ queue

+1
source

All Articles