Sunday, 5 August 2018

ActiveMQ: Delete a queue programmatically in Java

In this post, I am going to show you how can you delete a queue programmatically.

If the ActiveMQ instance is running on port 5050, you can see all the queues from below url.



As you see above image, you can able to see two queues ‘DEMO_QUEUE’ and ‘Hello World’ queues there.

Test.java
package com.sample.app;

import javax.jms.ConnectionFactory;
import javax.jms.JMSException;

import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.command.ActiveMQQueue;

public class Test {
 private static final String JMS_PROVIDER_URL = "tcp://127.0.0.1:5050";
 private static final String QUEUE = "DEMO_QUEUE";

 public static void main(String args[]) throws JMSException {
  ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(JMS_PROVIDER_URL);
  ActiveMQConnection connection = (ActiveMQConnection) connectionFactory.createConnection();

  connection.destroyDestination(new ActiveMQQueue(QUEUE));
  
  connection.close();
 }
}

When you ran above application, it deletes the queue ‘DEMO_QUEUE’.


In my next posts, you can learn more about JMS specification.

Previous                                                 Next                                                 Home

No comments:

Post a Comment