【问题标题】:Activemq jolokia rest api for deleting a queue?Activemq jolokia rest api用于删除队列?
【发布时间】:2014-11-03 07:30:37
【问题描述】:

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

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

但是要删除的是什么?

【问题讨论】:

    标签: rest activemq jolokia


    【解决方案1】:

    您应该使用以下 URL 模式:

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

    您可以通过 jolokia here 了解访问 JMX 操作的格式。

    【讨论】:

    • 试过了。错误原因:org.apache.http.ProtocolException:服务器未能响应有效的 HTTP 响应。
    • 61616 通常是 openwire 端口,而不是 HTTP 端口。我使用本地默认配置的 ActiveMQ 5.9.0 验证了答案中的 URL。当然,除了端口和主机名之外,您还必须更改MyBrokerMyQueue
    • 你有适合你的 curl 命令吗?我得到的只是尝试它时出错。
    • 这会删除 MyQueue。因为我在 mac 终端上运行了一些字符,所以使用反斜杠进行了转义。 curl --user admin:admin http://localhost:8161/hawtio/jolokia/exec/org.apache.activemq:type\=Broker,brokerName\=localhost/removeQueue\(java.lang.String\)/MyQueue
    【解决方案2】:

    这是一个 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());
    }
    

    【讨论】:

      猜你喜欢
      • 2018-01-30
      • 1970-01-01
      • 2021-03-08
      • 1970-01-01
      • 2016-11-09
      • 1970-01-01
      • 2012-08-17
      • 1970-01-01
      • 2011-03-03
      相关资源
      最近更新 更多