3
votes

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?

2

2 Answers

6
votes

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.

0
votes

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());
}