我希望做一个限制在ActiveMQ的一些队列的消费者,在hornetq(JBoss的,这是在MDB消费者的定义注释做)。 我无法找到的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
}
}