Java by itself does NOT support sessions. So, what exactly do you want to do? Stop your session accessing the queue? Then don't access it and remove (null) the references to it.
If you don't mind using a non-JMS API call then you can cast your Connection object to an ActiveMQConnection and call destroyDestination passing it an instance of the destination you want to remove. Provided there are no active consumers on that Destination it will be removed, otherwise you will get an exception indicating that you can't remove a Destination with an active consumer.
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);
}
}
}
}
}
Java by itself does NOT support sessions. So, what exactly do you want to do? Stop your session accessing the queue? Then don't access it and remove (null) the references to it.
If you don't mind using a non-JMS API call then you can cast your Connection object to an ActiveMQConnection and call destroyDestination passing it an instance of the destination you want to remove. Provided there are no active consumers on that Destination it will be removed, otherwise you will get an exception indicating that you can't remove a Destination with an active consumer.
Simple solution that does not use JMX it to cast connection to ActiveMQConnection and use its destroyDestination() method. Simple utility that uses that approach:
Dependency for Maven
you can do this with JMX via the 'removeQueue' operation...
see this page for a programmatic example:
http://www.consulting-notes.com/2010/08/monitoring-and-managing-activemq-with.html