<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 88, comments - 3, trackbacks - 0, articles - 0
      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

    通過rest api管理activemq

    Posted on 2016-10-22 17:31 Milo的海域 閱讀(1436) 評論(0)  編輯  收藏 所屬分類: Java

    知道activemq現在已經支持了rest api, 但是官方對這部分的介紹一筆帶過 (http://activemq.apache.org/rest.html),


    通過google居然也沒搜到一些有用的, 比如像刪除一個destination, 都是問的多,然后沒下文. 于是花了一些心思研究了一下:


    首先通過rest api獲取當前版本所有已支持的協議

        http://172.30.43.206:8161/api/jolokia/list


    然后根據json輸出關于removeTopic, removeQueue的mbean實現通過rest api刪除destination的方法, 注意到用GET請求而不是POST,不然會報錯 (官網的例子里用的wget給的靈感, 開始用了POST老報錯)


    import org.apache.activemq.command.ActiveMQQueue;
    import org.apache.activemq.command.ActiveMQTopic;
    import org.apache.http.auth.AuthScope;
    import org.apache.http.auth.UsernamePasswordCredentials;
    import org.apache.http.impl.client.BasicCredentialsProvider;
    import org.apache.http.impl.client.DefaultHttpClient;
    import org.springframework.http.HttpEntity;
    import org.springframework.http.HttpHeaders;
    import org.springframework.http.HttpMethod;
    import org.springframework.http.MediaType;
    import org.springframework.http.ResponseEntity;
    import org.springframework.http.client.ClientHttpRequestFactory;
    import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
    import org.springframework.web.client.RestTemplate;

    import javax.jms.Destination;
    import javax.jms.JMSException;
    import java.util.Arrays;


    public class MessageQueueAdmin {
        
    private static final RestTemplate restTemplate = getRestTemplate("admin""admin");

        
    private static String brokerHost = "172.30.43.206";
        
    private static String adminConsolePort = "8161";
        
    private static String protocol = "http";

        
    public static void removeDestination(Destination destination) throws JMSException {
            String destName, destType;
            
    if (destination instanceof ActiveMQQueue) {
                destName 
    = ((ActiveMQQueue) destination).getQueueName();
                destType 
    = "Queue";
            } 
    else {
                destName 
    = ((ActiveMQTopic) destination).getTopicName();
                destType 
    = "Topic";
            }

            
    // build urls
            String url = String.format("%s://%s:%s/api/jolokia/exec/org.apache.activemq:" +
                    
    "brokerName=localhost,type=Broker/remove%s/%s", protocol, brokerHost, adminConsolePort, destType, destName);
            System.out.println(url);
            
    // do operation
            HttpHeaders headers = new HttpHeaders();
            headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
            HttpEntity
    <String> entity = new HttpEntity<String>("parameters", headers);
            ResponseEntity response 
    = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
            System.out.println(response.getBody());
        }

        
    public static void main(String[] args) throws JMSException {
            ActiveMQTopic topic 
    = new ActiveMQTopic("test-activemq-topic");
            removeDestination(topic);
        }


        
    private static RestTemplate getRestTemplate(String user, String password) {
            DefaultHttpClient httpClient 
    = new DefaultHttpClient();
            BasicCredentialsProvider credentialsProvider 
    = new BasicCredentialsProvider();
            credentialsProvider.setCredentials(AuthScope.ANY, 
    new UsernamePasswordCredentials(user, password));
            httpClient.setCredentialsProvider(credentialsProvider);
            ClientHttpRequestFactory rf 
    = new HttpComponentsClientHttpRequestFactory(httpClient);

            
    return new RestTemplate(rf);
        }
    }

    其他的請求,應該都是類似jolokia的exec get request的格式:


    https://jolokia.org/reference/html/protocol.html#exec


    <base url>/exec/<mbean name>/<operation name>/<arg1>/<arg2>/.
    主站蜘蛛池模板: 亚洲乱码在线卡一卡二卡新区| 亚洲成AV人片在线观看ww| 亚洲婷婷综合色高清在线| 久久久久国色av免费看| 亚洲成AV人片在线观看| 特级无码毛片免费视频尤物| 亚洲天天做日日做天天欢毛片| 日韩电影免费观看| 久久久久亚洲AV片无码下载蜜桃| 16女性下面扒开无遮挡免费| 亚洲视频中文字幕| 2021免费日韩视频网| 亚洲欧美日韩中文字幕一区二区三区| 日本大片在线看黄a∨免费| 国产亚洲精品成人久久网站| 亚洲欧洲日本在线| 久久免费高清视频| 亚洲神级电影国语版| 成年人免费网站在线观看| 色偷偷亚洲第一综合网| 国产偷国产偷亚洲高清日韩| 日本在线免费播放| 7777久久亚洲中文字幕| 国产免费拔擦拔擦8x| a毛看片免费观看视频| 亚洲福利一区二区精品秒拍| 国产美女做a免费视频软件| 和老外3p爽粗大免费视频| 久久亚洲AV成人出白浆无码国产 | 97青青草原国产免费观看| 亚洲人成免费网站| 免费v片视频在线观看视频| 99久久国产精品免费一区二区| 亚洲欧洲国产成人精品| 国产成人精品免费视频大全五级| 青柠影视在线观看免费高清 | 最新中文字幕电影免费观看| eeuss草民免费| 亚洲国产成人精品无码一区二区 | 亚洲免费在线视频播放| 精品国产日韩亚洲一区|