java - 如何在短时间内按需销毁上千个ActiveMQ队列?

标签 java multithreading apache-camel activemq

我们使用数千个队列在系统内传递数据。出现的问题是,销毁它总是需要很多时间,而且我们必须等到队列不再被使用。

为此,我们目前使用以下方法

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/

相关文章:

java - ClassNotFoundException 公共(public)软件 CameraFragment

调用函数时java子类状态不改变

java - 内存不一致或线程干扰或两者兼而有之?

c++ - 文件线程

ruby-on-rails - 在我的 Rails Controller 方法中运行线程

java - Camel : Add TypeConverter in Test Case

java - Play Java Forms 不会递归检查约束

java - 使用 spring-hibernate 的 2 个不同的数据库连接

java - Apache Camel Junit 模拟问题

java - Camel 从 Tracer 到 BacklogTracer