3

有没有办法在 5.9.0 上使用 ActiveMQ rest api 删除队列?我知道你可以用

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

但是要删除的是什么?

4

2 回答 2

6

您应该使用以下 URL 模式:

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

您可以在此处阅读有关通过 jolokia 访问 JMX 操作的格式。

于 2014-09-09T20:30:52.793 回答
0

这是一个可以做到的java f'n:

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());
}
于 2014-09-12T21:10:30.077 回答