3

Is there a way to delete a queue with ActiveMQ rest api on 5.9.0? I know you can purge a queue with

"http://" + host + ":" + port + "/api/jolokia/exec/org.apache.activemq:brokerName=localhost,destinationName=" + queueName + ",destinationType=Queue,type=Broker/purge()";

But what is the one for deleting?

Nicholas DiPiazza
  • 10,029
  • 11
  • 83
  • 152

3 Answers3

6

You should use the following URL pattern:

http://hostname:8161/hawtio/jolokia/exec/org.apache.activemq:type=Broker,brokerName=MyBroker/removeQueue(java.lang.String)/MyQueue

You can read about the format to access JMX operations thorugh jolokia here.

Petter Nordlander
  • 22,053
  • 5
  • 50
  • 84
  • 1
    Tried it. Error Caused by: org.apache.http.ProtocolException: The server failed to respond with a valid HTTP response. – Nicholas DiPiazza Sep 10 '14 at 18:55
  • My URL was: http://192.168.111.80:61616/hawtio/jolokia/exec/org.apache.activemq:type=Broker,brokerName=localhost/removeQueue(java.lang.String)/0602f86e-86c5-4758-94aa-b2cb499997fd – Nicholas DiPiazza Sep 10 '14 at 18:57
  • 61616 is typically the openwire port, not the HTTP port. I verified the URL in my answer with a local default configured ActiveMQ 5.9.0. Of course, you have to change `MyBroker`and `MyQueue`aside from the port and hostname. – Petter Nordlander Sep 10 '14 at 19:30
  • Do you have a curl command that worked for you? I get nothing but errors trying it. – Nicholas DiPiazza Sep 11 '14 at 15:58
  • This removes MyQueue. Some characters are escaped with backslash since i ran it on a mac terminal. `curl --user admin:admin http://localhost:8161/hawtio/jolokia/exec/org.apache.activemq:type\=Broker,brokerName\=localhost/removeQueue\(java.lang.String\)/MyQueue` – Petter Nordlander Sep 11 '14 at 17:45
  • that java.lang.String stuff made mine fail on ActiveMQ 5.9.0. Once I removed that it worked: – Nicholas DiPiazza Sep 12 '14 at 20:20
  • Hmm. Odd, it works for me. It's great that you managed to get it working though. – Petter Nordlander Sep 13 '14 at 07:50
1

This one works.

curl --location --request GET 'http://localhost:8161/api/jolokia/exec/org.apache.activemq:type=Broker,brokerName=<brokerName>/removeQueue/<queueName>' --header 'Authorization: Basic <token>' \

Courtesy: brettPorter

Hari R
  • 103
  • 2
  • 11
0

Here is a java f'n that does it:

public static String removeQueue(String queueName) throws ClientProtocolException, IOException, URISyntaxException {

    String username = "admin";
    String password = "admin";
    URI mqUrl = new URI( YOUR ACTIVE MQ URI HERE );
    HttpHost targetHost = new HttpHost(mqUrl.getHost(), mqUrl.getPort(), "http");

    CredentialsProvider credsProvider = new BasicCredentialsProvider();
    credsProvider.setCredentials(AuthScope.ANY, 
      new UsernamePasswordCredentials(username, password));

    AuthCache authCache = new BasicAuthCache();
    authCache.put(targetHost, new BasicScheme());

    // Add AuthCache to the execution context
    final HttpClientContext context = HttpClientContext.create();
    context.setCredentialsProvider(credsProvider);
    context.setAuthCache(authCache);

    HttpClient client = HttpClientBuilder.create().build();

    String uri = "http://" + mqUrl.getHost() + ":" + mqUrl.getPort() + "/hawtio/jolokia/exec/org.apache.activemq:type=Broker,brokerName=localhost/removeQueue/" + queueName;

    HttpResponse response = client.execute(new HttpGet(uri), context);
    if (response.getStatusLine().getStatusCode() != 200) {
        throw new IOException(response.getStatusLine().toString());
    }
    return IOUtils.toString(response.getEntity().getContent());
}
Nicholas DiPiazza
  • 10,029
  • 11
  • 83
  • 152