ActiveMQ从Java删除队列 [英] ActiveMQ delete queue from java
本文介绍了ActiveMQ从Java删除队列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从Java程序中删除activemq中的队列?是否有像session.delelteQueue()这样的东西?
How could I delete a queue in activemq from java program? Is there anything like session.delelteQueue()?
感谢M。
推荐答案
不使用JMX的简单解决方案它将连接强制转换为ActiveMQConnection并使用其destroyDestination()方法。
使用该方法的简单实用程序:
Simple solution that does not use JMX it to cast connection to ActiveMQConnection and use its destroyDestination() method. Simple utility that uses that approach:
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从Java删除队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文