最近做一个东西要用到activemq,同时希望能自己写一个页面来管理队列中的消息(list, del等)查阅了官网,说5.8以后的版本支持rest方式。但是官网却没有详细的介绍。
于是我就用chrom浏览器,跟踪8161端口的web管理界面,把http的请求抓出来,整理了下,放在下面,希望能帮助到大家。具体如下:(codec是队列名)
一. 获取队列内消息:
1. cmd方式:/data/yunfei/apache-activemq-5.9.0/bin/activemq-admin browse --amqurl tcp://localhost:61616 codec
2. URL方式:
curl -u "admin:admin" -d "{\"type\":\"exec\",\"mbean\":\"org.apache.activemq:type=Broker,brokerName=localhost,destinationType=Queue,destinationName=codec\",\"operation\":\"browse()\"}" http://localhost:8161/hawtio/jolokia/
curl -u "admin:admin" -d "{\"type\":\"exec\",\"mbean\":\"org.apache.activemq:type=Broker,brokerName=localhost,destinationType=Queue,destinationName=codec\",\"operation\":\"browseAsTable()\"}" http://localhost:8161/hawtio/jolokia/
2. URL方式:
curl -u "admin:admin" -d "{\"type\":\"exec\",\"mbean\":\"org.apache.activemq:type=Broker,brokerName=localhost,destinationType=Queue,destinationName=codec\",\"operation\":\"browse()\"}" http://localhost:8161/hawtio/jolokia/
curl -u "admin:admin" -d "{\"type\":\"exec\",\"mbean\":\"org.apache.activemq:type=Broker,brokerName=localhost,destinationType=Queue,destinationName=codec\",\"operation\":\"browseAsTable()\"}" http://localhost:8161/hawtio/jolokia/
二.删除队列中等待的某个消息:
1. cmd方式:/data/yunfei/apache-activemq-5.9.0/bin/activemq-admin purge --msgsel "JMSType='111'" codec
注:JMSType的值对应vid
2. URL方式:
curl -u "admin:admin" -d "{\"type\":\"exec\",\"mbean\":\"org.apache.activemq:type=Broker,brokerName=localhost,destinationType=Queue,destinationName=codec\",\"operation\":\"removeMessage(java.lang.String)\",\"arguments\":[\"ID:tj-10-47-9909-1389693308017-2:25:-1:1:1\"]}" http://localhost:8161/hawtio/jolokia/
需要修改的是\"arguments\":[\"ID:tj-10-47-9909-1389693308017-10:1:1:1:1\" 这里面的messageid,改成要删除的id
注:JMSType的值对应vid
2. URL方式:
curl -u "admin:admin" -d "{\"type\":\"exec\",\"mbean\":\"org.apache.activemq:type=Broker,brokerName=localhost,destinationType=Queue,destinationName=codec\",\"operation\":\"removeMessage(java.lang.String)\",\"arguments\":[\"ID:tj-10-47-9909-1389693308017-2:25:-1:1:1\"]}" http://localhost:8161/hawtio/jolokia/
需要修改的是\"arguments\":[\"ID:tj-10-47-9909-1389693308017-10:1:1:1:1\" 这里面的messageid,改成要删除的id
三.删除队列中所有消息
1.cmd方式:/data/yunfei/apache-activemq-5.9.0/bin/activemq-admin purge codec
2.URL方式:
curl -u "admin:admin" -d "{\"type\":\"exec\",\"mbean\":\"org.apache.activemq:type=Broker,brokerName=localhost,destinationType=Queue,destinationName=codec\",\"operation\":\"purge()\"}" http://localhost:8161/hawtio/jolokia/
2.URL方式:
curl -u "admin:admin" -d "{\"type\":\"exec\",\"mbean\":\"org.apache.activemq:type=Broker,brokerName=localhost,destinationType=Queue,destinationName=codec\",\"operation\":\"purge()\"}" http://localhost:8161/hawtio/jolokia/