09 April 2014

Adding/Removing queue to/from ActiveMQ via command line

Bambitroll @ 10:09

There is a way to add/remove queues on ActiveMQ from the command line.
It uses the REST interface of Jolokia which comes with Hawtio on ActiveMQ 5.9.0.

The first 2 commands contain all you need to create and then to remove the queue called q_titi, using the user admin/admin:
curl -u admin:admin -d "{\"type\":\"exec\",\"mbean\":\"org.apache.activemq:type=Broker,brokerName=localhost\",\"operation\":\"addQueue(java.lang.String)\",\"arguments\":[\"q_titi\"]}" http://localhost:8161/hawtio/jolokia/

curl -u admin:admin -d "{\"type\":\"exec\",\"mbean\":\"org.apache.activemq:type=Broker,brokerName=localhost\",\"operation\":\"removeQueue(java.lang.String)\",\"arguments\":[\"q_titi\"]}" http://localhost:8161/hawtio/jolokia/


The next 2 command do the same for the queue q_OMG but use the attached files for the necessary JSON request (so no more need to escape the double quotes and way more readable!):

curl -u admin:admin -d "@/tmp/jmr/createQ_json.txt" http://localhost:8161/hawtio/jolokia/
curl -u admin:admin -d "@/tmp/jmr/removeQ_json.txt" http://localhost:8161/hawtio/jolokia/

createQ_json.txt looks like this:
{
 "type":"exec",
 "mbean":"org.apache.activemq:type=Broker,brokerName=localhost",
 "operation":"addQueue(java.lang.String)",
 "arguments":["q_OMG"]
}


removeQ_json.txt looks like this:
{
 "type":"exec",
 "mbean":"org.apache.activemq:type=Broker,brokerName=localhost",
 "operation":"removeQueue(java.lang.String)",
 "arguments":["q_OMG"]
}


More info here:
Monitoring ActiveMQ via HTTP http://www.jakubkorab.net/2013/11/monitoring-activemq-via-http.html

3 Response to "Adding/Removing queue to/from ActiveMQ via command line"

  1. Rajashree Khare said...

    I am using ActiveMQ 5.5. Would I be able to use the same commands to add/remove queues? If not could you please help me how can I delete queues on this version of AMQ via command line

  2. Rajashree Khare said...

    Will this work if JMX is disabled?

  3. Bambitroll said...

    Hi Rajashree,
    My example uses the REST interface of Jolokia, which allows you to issue a HTTP command which is then converted to a JMX request on the server which in turn does what you want on ActiveMQ.
    I am not sure if ActiveMQ 5.5 supports Jolokia, but if does not then you can not use these commands.
    This will not work if JMX is disabled.

Post a Comment