繁体   English   中英

如何检查 Activemq 上是否存在队列

[英]how can I check if a queue exists on Activemq

我有这个方法,当数据队列不存在时抛出异常,但不存在。 你有其他方法来解决这个问题吗?

public void checkDataQueue(String dataQueue) throws JMSException {

          Connection connection = null;
          Session session = null;
          connection = jmsTemplate.getConnectionFactory().createConnection();
          session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

          Queue queue = session.createQueue(dataQueue);
          QueueBrowser browser = session.createBrowser(queue);
      }

默认情况下,ActiveMQ 5.x 按需创建队列,因此您可能已更改默认配置以禁止这种情况,在这种情况下,如果您遇到不存在的队列,应该会发生错误,您应该检查并处理它。 如果您需要确定,那么代理会提供一个JMX接口来查询有关代理统计信息等的信息。还有其他监控方式,例如通过 Jolokia 管理接口使用 Rest 样式调用。

谢谢蒂姆,我用这些方法解决了它。

public boolean existDataQueue(String dataQueue) throws JMSException {
            boolean response = false;
            ActiveMQConnectionFactory activeMQConnectionFactory =
                new ActiveMQConnectionFactory();
            activeMQConnectionFactory.setBrokerURL(brokerUrl);
            ActiveMQConnection connection = (ActiveMQConnection)activeMQConnectionFactory.createConnection();

            connection.start();

            DestinationSource ds = connection.getDestinationSource();

            Set<ActiveMQQueue> queues = ds.getQueues();

            for (ActiveMQQueue activeMQQueue : queues) {
                try {
                    if(activeMQQueue.getQueueName().equalsIgnoreCase(dataQueue)) {
                        response = true;
                    }
                } catch (JMSException e) {
                    e.printStackTrace();
                }
            }
            connection.close();
            return response;
      }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM