<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>/.
    主站蜘蛛池模板: 亚洲国产成人精品无码一区二区| 国产免费资源高清小视频在线观看| a在线观看免费视频| 国产在线观看免费视频软件| 亚洲国产成人久久一区WWW| 在线亚洲精品福利网址导航| 亚洲美女视频免费| 日韩国产精品亚洲а∨天堂免| 中国极品美軳免费观看| 亚欧免费视频一区二区三区| 成年女人午夜毛片免费看| 亚洲人成无码网站久久99热国产| 亚洲国产精品成人精品软件| 曰韩无码AV片免费播放不卡| 99久久99久久免费精品小说 | 亚洲AV成人一区二区三区观看 | 青青青免费国产在线视频小草| 午夜爱爱免费视频| 亚洲国产精品无码成人片久久| 亚洲综合国产成人丁香五月激情 | 无码中文在线二区免费| 亚洲爆乳无码专区| 四虎成年永久免费网站| 亚洲色欲色欱wwW在线| 免费a级黄色毛片| 亚洲色欲色欲www在线播放| 五月天婷亚洲天综合网精品偷| 亚洲国产人成在线观看| 午夜毛片不卡免费观看视频| 一区二区三区免费看| 国产zzjjzzjj视频全免费| 国产免费A∨在线播放| 四虎成人精品在永久免费| 91在线视频免费观看| 亚洲国产精品视频| 日日麻批免费40分钟无码| 亚洲 日韩经典 中文字幕| 国产成人A在线观看视频免费| 亚洲免费福利视频| 亚洲国产成人久久精品99 | 深夜a级毛片免费无码|