我们使用数千个队列在系统内传递数据。出现的问题是,销毁它总是需要很多时间,而且我们必须等到队列不再被使用。
为此,我们目前使用以下方法
try {
_consumer.getEndpoint().stop();
_consumer.stop();
}
catch (Exception ex) {
System.out.println("Error: " + ex.getMessage());
}
// Wait a little, so that ActiveMQ has time to realize that the endpoint is destroyed,
// which is necessary to be done before the queue is destroyed,
// otherwise we get an "Error: Destination still has an active subscription: queue://receive:XXX":
try {
Thread.sleep(1);
}
catch (InterruptedException ex) {
System.out.println("Error: " + ex.getMessage());
}
// Destroy queue:
String shortRxQueueName = _rxQueueName.replace("activemq:queue:", "");
try {
activeMQConnection.destroyDestination(new ActiveMQQueue(shortRxQueueName));
}
catch (JMSException ex) {
System.out.println("Error: " + ex.getMessage());
}
即使我们尝试忽略与代理的连接并仅使用当前可用的 activeMQConnection
,停止 300 个队列也需要大约 50 秒。
3402: Stopping clients...
53500: Stopping camel context...
因此,对于每个销毁队列,我们消耗 0.16 秒。
如何让它更快? Camel 是否包含池或缓存队列之类的东西来执行操作?
最佳答案
我不知道这是否适合您的要求,但您可以看看这个
ActiveMQ - delete/purge all queue via command line
它的作用是,当 activemq 启动时,它会删除所有队列和消息。
希望这有帮助! 祝你好运!
关于java - 如何在短时间内按需销毁上千个ActiveMQ队列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29820530/