gpt4 book ai didi

activemq - ActiveMQ从Java删除队列

转载 作者:行者123 更新时间:2023-12-04 13:33:34 25 4
gpt4 key购买 nike

如何从Java程序中删除activemq中的队列?是否有像session.delelteQueue()这样的东西?

谢谢M.

最佳答案

一个简单的解决方案,不使用JMX将其强制转换为ActiveMQConnection并使用其destroyDestination()方法。
使用该方法的简单实用程序:

import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.command.ActiveMQQueue;
import javax.jms.JMSException;

/**
* simple class to delete a queue form the activeMQ broker
* @author josef.
*/
public class QueueDeleter {
public static void main(String[] args) {
if (args.length != 2) {
System.out.println("please specify broker URL and queue name, \nexample: tcp://localhost:61616 queue1");
System.exit(2);
}
ActiveMQConnection conn = null;
try {
conn = (ActiveMQConnection) new ActiveMQConnectionFactory(args[0]).createConnection();
conn.destroyDestination(new ActiveMQQueue(args[1]));
} catch (JMSException e) {
System.out.println("Error connecting to the browser please check the URL" + e);
} finally {
if (conn != null) {
try {
conn.close();
} catch (JMSException e) {
System.out.println("Error closing connection" + e);
}
}
}
}
}

对Maven的依赖
    <dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-core</artifactId>
<version>5.7.0</version>
</dependency>

关于activemq - ActiveMQ从Java删除队列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12062677/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com