javaactivemq-classicmessagingjmx

how to delete a specific queue in activemq


i want to delete a specific queue from consumer after getting the message from queue in activemq. i read many articles but none of them giving good explanation.i can provide either queue name or correlationID for deleting the queue. please give some suggestion.

version :-Activemq 5.8.0 . advance thanks


Solution

  • I got the answer.delete a queue programmatically from a java program

     JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi");
    JMXConnector jmxc = JMXConnectorFactory.connect(url);
    MBeanServerConnection conn = jmxc.getMBeanServerConnection();
    
    String operationName="removeQueue"; //operation like addQueue or removeQueue
    String parameter="Payment_Check";   // Queue name
    ObjectName activeMQ = new ObjectName("org.apache.activemq:brokerName=localhost,type=Broker");
    if(parameter != null) {
        Object[] params = {parameter};
        String[] sig = {"java.lang.String"};
        conn.invoke(activeMQ, operationName, params, sig);
    } else {
        conn.invoke(activeMQ, operationName,null,null);
    } 
    

    you want to change in activemq config file.in default createConnector="false".change to createConnector="true".otherwise you will get error like

     Exception in thread "main" java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.ServiceUnavailableException.
    

    this concept is explained in "ben.odey"'s article "managing ActiveMQ with JMX APIs". Link:- managing ActiveMQ with JMX APIs