<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的海域 閱讀(1446) 評論(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>/.
    主站蜘蛛池模板: 久9热免费精品视频在线观看| 亚洲伦理一区二区| 亚洲色精品VR一区区三区| 色综合久久精品亚洲国产| 日韩a毛片免费观看| 亚洲成A人片在线观看无码不卡 | 永久黄网站色视频免费观看| 亚洲精品无码日韩国产不卡?V | 免费无码一区二区| 免费国产综合视频在线看| 欧美大尺寸SUV免费| 97在线观看永久免费视频| 免费无码成人AV在线播放不卡| 两个人看的www高清免费视频| AV大片在线无码永久免费| 国产亚洲精品成人AA片新蒲金| 最新亚洲卡一卡二卡三新区| 免费成人高清在线视频| 免费人妻无码不卡中文字幕18禁| 亚洲视频在线观看网站| 亚洲黄色免费电影| 我的小后妈韩剧在线看免费高清版 | 四虎影视www四虎免费| 成人毛片18女人毛片免费96| 国产亚洲综合成人91精品| 亚洲精品无码永久在线观看男男| 久9这里精品免费视频| 亚洲午夜久久久久久噜噜噜| 久久精品熟女亚洲av麻豆| 无码人妻一区二区三区免费视频| 免费影院未满十八勿进网站| 亚洲国产精品无码中文字| 日本中文字幕免费看| 四虎影视永久免费观看| 亚洲中文字幕乱码熟女在线| 免费观看美女用震蛋喷水的视频| 日韩成人免费aa在线看| 亚洲综合另类小说色区色噜噜| 亚洲av综合av一区二区三区| 日韩精品无码免费专区午夜不卡| 免费大香伊蕉在人线国产 |