[英]ActiveMQ throttling consumer
我想对hornetq中的activeMQ中某个队列的使用者进行节流(对于jboss,这是通过对mdb Consumer的定义进行注释来完成的)。 我在activemq的文档中找不到任何类似的东西,我发现最接近的是这个
consumer.recvDelay 0 ms Pause consumer for recvDelay milliseconds with each message (allows consumer throttling).
来自: http : //activemq.apache.org/activemq-performance-module-users-manual.html
但是我找不到在Java中的方法。
提前致谢,
问候。
编辑:这是ActiveMQManager代码和使用者代码:
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);
}
}
}
使用者代码非常简单(对于此示例):
public class TestConsumer implements MessageListener {
@Override
public void onMessage(Message message) {
//Do something with the message
}
}
这取决于所使用的消费者技术...但是这里有一些选择
您可以手动在用户代码中引入延迟(这不是一门确切的科学方法,但这会限制吞吐量)
您还可以通过设置JMS连接的maxConcurrentConsumers属性来控制使用者使用的线程数...也就是说,这不会限制消息吞吐量,只是限制了使用者使用的并发级别
更好的是,您可以使用调节器EIP实施来设置每个时间段要消耗的确切消息数
例如,使用骆驼节流阀这是微不足道的
from("activemq:queueA").throttle(10).to("activemq:queueB")
使用ActiveMQ,您可以设置使用者的预取限制: http : //activemq.apache.org/what-is-the-prefetch-limit-for.html
要配置它,您可以使用连接URL(大多数配置可以使用URL完成)或Java API。
有关更有趣的参数: http : //activemq.apache.org/connection-configuration-uri.html
考虑到骆驼节流阀在节流阀被阻塞时将其保持在内存中。 因此,如果您有100个队列使用者,并且服务器(公开SOAP服务)速度很慢,则内存中最多可能有100个交换!
为此发布此问题: 在ActiveMQ队列上侦听的所有JMS使用者的油门消耗率
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.