Eduardo Z.
Eduardo Z.

Reputation: 643

ActiveMQ - Removing queues programmatically

Fellow StackOverflowers, is there a way for me to remove a queue or a topic in ActiveMQ programmatically? I am using ActiveMQ's standard persistency, and my application requires that, on startup, all new queues be dynamically re-created (unless there are messages stored in the queue, in which case, the queue should remain to exist).

I am also creating all queues programmatically through sessions. Is there an equivalent to that procedure, only to delete a queue? Querying and iterating through the existing queues would also be useful, but i haven't found a way to do that yet.

Upvotes: 6

Views: 15176

Answers (4)

Yu Jiaao
Yu Jiaao

Reputation: 4714

If you use spring JmsTemplate, you can do it this way:

Connection cn = getJmsTemplate().getConnectionFactory().createConnection();
ActiveMQDestination destination = ActiveMQDestination.createDestination(queueName, ActiveMQDestination.QUEUE_TYPE);             

if(cn instanceof PooledConnection){
    ((PooledConnection)cn).getConnection().destroyDestination(destination );
}

Upvotes: 2

Andrejs
Andrejs

Reputation: 27677

You can also Delete Destinations that are inactive for some period of time. Available since Active MQ 5.4

Alternatively if you are running ActiveMQ embedded you can use the API to remove destinations: Region.removeDestination

Upvotes: 6

bsnyder
bsnyder

Reputation: 1199

To remove a destination from ActiveMQ programmatically, you will need to do so via JMX using the removeTopic and removeQueue methods on the broker MBean (org.apache.activemq:BrokerName=localhost,Type=Broker). I have posted some example code to demonstrate this, including the use of the removeTopic method, over on Gist:

http://gist.github.com/439668

Hope that helps.

Bruce

Upvotes: 4

nos
nos

Reputation: 229088

While there's not a lot of concrete examples, there's some documentation about it here : http://activemq.apache.org/how-do-i-purge-a-queue.html

Upvotes: 0

Related Questions