如何从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>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)