0

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

2
  • 1
    how do you want to delete the queue, from java code, or some admin console? There is API on JMS to delete a queue, and ActiveMQ has JMX API to delete queues also Nov 11, 2013 at 9:40
  • @ClausIbsen Thanks for the reply. i got the answer. i want to delete from java code.i did using this link consulting-notes.com/2010/08/…
    – nichu09
    Nov 11, 2013 at 10:18

2 Answers 2

1

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

1
  • Needed to use this as the ObjectName: org.apache.activemq:BrokerName=localhost,Type=Broker Dec 20, 2014 at 1:16
0

I also get like your problem. I fixed like that here. It is using QueueViewMBean. Which have removeMessage function. You just need to pass messageid.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.