Artemis 在绑定时抛出 Cannot delete queue - 它有消费者

Artemis is throwing Cannot delete queue on binding - it has consumers

我们在连接到 ActiveMQ Artemis 2.17.0 实例的集群中有多个应用程序服务器。其中一个应用程序将充当主节点,其余应用程序服务器将充当从节点。

作为数据处理周期的一部分,在生成或使用消息之前,master 将尝试删除队列并重新创建队列。

下面是我们在 Artemis 日志中观察到的异常堆栈

2022-01-03 19:14:55,603 WARN  [org.apache.activemq.artemis.core.server] Errors occurred during the buffering operation : ActiveMQIllegalStateException[errorType=ILLEGAL_STATE message=AMQ229025: Cannot delete queue -1.36.1.level-1.queue on binding -1.36.1.level-1.queue - it has consumers = org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding]
    at org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl.destroyQueue(ActiveMQServerImpl.java:2338) [artemis-server-2.17.0.jar:2.17.0]
    at org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl.destroyQueue(ActiveMQServerImpl.java:2306) [artemis-server-2.17.0.jar:2.17.0]
    at org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl.destroyQueue(ActiveMQServerImpl.java:2297) [artemis-server-2.17.0.jar:2.17.0]
    at org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl.destroyQueue(ActiveMQServerImpl.java:2277) [artemis-server-2.17.0.jar:2.17.0]
    at org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl.destroyQueue(ActiveMQServerImpl.java:2270) [artemis-server-2.17.0.jar:2.17.0]
    at org.apache.activemq.artemis.core.protocol.openwire.OpenWireConnection.removeDestination(OpenWireConnection.java:1062) [artemis-openwire-protocol-2.17.0.jar:2.17.0]
    at org.apache.activemq.artemis.core.protocol.openwire.OpenWireConnection$CommandProcessor.processRemoveDestination(OpenWireConnection.java:1206) [artemis-openwire-protocol-2.17.0.jar:2.17.0]
    at org.apache.activemq.command.DestinationInfo.visit(DestinationInfo.java:124) [activemq-client-5.16.0.jar:5.16.0]
    at org.apache.activemq.artemis.core.protocol.openwire.OpenWireConnection.act(OpenWireConnection.java:323) [artemis-openwire-protocol-2.17.0.jar:2.17.0]
    at org.apache.activemq.artemis.utils.actors.Actor.doTask(Actor.java:33) [artemis-commons-2.17.0.jar:2.17.0]
    at org.apache.activemq.artemis.utils.actors.ProcessorBase.executePendingTasks(ProcessorBase.java:65) [artemis-commons-2.17.0.jar:2.17.0]
    at org.apache.activemq.artemis.utils.actors.OrderedExecutor.doTask(OrderedExecutor.java:42) [artemis-commons-2.17.0.jar:2.17.0]
    at org.apache.activemq.artemis.utils.actors.OrderedExecutor.doTask(OrderedExecutor.java:31) [artemis-commons-2.17.0.jar:2.17.0]
    at org.apache.activemq.artemis.utils.actors.ProcessorBase.executePendingTasks(ProcessorBase.java:65) [artemis-commons-2.17.0.jar:2.17.0]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [rt.jar:1.8.0_292]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [rt.jar:1.8.0_292]
    at org.apache.activemq.artemis.utils.ActiveMQThreadFactory.run(ActiveMQThreadFactory.java:118) [artemis-commons-2.17.0.jar:2.17.0]

你能告诉我什么时候会发生这种情况以及如何避免吗?

请在下面找到用于删除队列的示例代码:

public void dropQueue() throws JMSException { 
   try { 
      if (connection instanceof ActiveMQConnection && destination instanceof ActiveMQDestination) {
         ((ActiveMQConnection)connection).destroyDestination((ActiveMQDestination)destination);
      } else {
         log.info("Dropping queue : " + queueName + " not supported."); 
      }
   } catch(JMSException e) { 
      throw e; 
   }
}

代理正在记录此 WARN 消息(而不是删除队列),因为正如 WARN 消息所示,您尝试删除的队列上有消费者:

Cannot delete queue...it has consumers

您可以通过不删除队列或在删除队列之前从该队列中移除所有使用者来避免这种情况。

一般来说,客户端删除代理上的队列不是一个好主意,因为队列是共享资源,可能会被其他客户端使用。