• 大小: 896KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-15
  • 语言: 其他
  • 标签: rabbitmq  

资源简介

包含通过http方式调用rabbitmq对外接口,如查看队列的有效性、获取交换机等信息 包含通过http方式调用rabbitmq对外接口,如查看队列的有效性、获取交换机等信息 包含通过http方式调用rabbitmq对外接口,如查看队列的有效性、获取交换机等信息 包含通过http方式调用rabbitmq对外接口,如查看队列的有效性、获取交换机等信息

资源截图

代码片段和文件信息

package com.test;

import javax.xml.bind.DatatypeConverter;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.conn.scheme.PlainSocketFactory;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.PoolingClientConnectionManager;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpParams;
import org.apache.http.util.EntityUtils;


public class Test {

public static void main(String[] args) throws Exception {
// /api/queues/vhost/name
// /api/queues
String httpurl = “http://server:15672/api/queues/%2F/sitech.devops.deploy.queue/bindings“;
/**
 * 1.初始化client
 */
String CODE_ENCODING = “UTF-8“;
HttpParams httpParams = new BasicHttpParams();
httpParams.setParameter(“charset“ CODE_ENCODING);
SchemeRegistry schreg = new SchemeRegistry();    
schreg.register(new Scheme(“http“80PlainSocketFactory.getSocketFactory()));   
schreg.register(new Scheme(“https“ 443 SSLSocketFactory.getSocketFactory()));
PoolingClientConnectionManager pccm = new PoolingClientConnectionManager(schreg);  
pccm.setDefaultMaxPerRoute(20); //每个主机的最大并行链接数   
pccm.setMaxTotal(100); //客户端总并行链接最大数 
DefaultHttpClient client =  new DefaultHttpClient(pccmhttpParams); 

/**
 * 2.连接
 */
HttpGet get = new HttpGet(httpurl);
get.addHeader(“Content-Type“ “application/json;charset=“ + CODE_ENCODING);
get.setHeader(“Accept“ “application/json“);
get.setHeader(“Content-Type“ “application/json;charset=“ + CODE_ENCODING);

String authorization = DatatypeConverter.printbase64Binary(“guest:guest“.getBytes(“UTF-8“));
System.out.println(authorization);
get.setHeader(“Authorization“ “Basic “+authorization);

HttpResponse res = client.execute(get);
int statusCode = res.getStatusLine().getStatusCode();
// 判断返回编码是否为200
if (statusCode != 200 && statusCode != 201) {
throw new Exception(“Get “ + httpurl + “Error!Response Code “ + statusCode);
}
HttpEntity entity = res.getEntity();
String response = EntityUtils.toString(entity CODE_ENCODING);
System.out.println(response);
}

}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        561  2018-03-01 15:33  RabbitMQHttpApi\.classpath

     文件        391  2018-03-01 15:31  RabbitMQHttpApi\.project

     文件        598  2018-03-01 15:31  RabbitMQHttpApi\.settings\org.eclipse.jdt.core.prefs

     文件       3857  2018-03-01 15:36  RabbitMQHttpApi\bin\com\test\Test.class

     文件     305001  2017-06-24 09:34  RabbitMQHttpApi\lib\commons-httpclient-3.1.jar

     文件      52915  2016-10-13 16:15  RabbitMQHttpApi\lib\commons-logging-1.1.jar

     文件     433368  2018-02-01 09:14  RabbitMQHttpApi\lib\httpclient-4.2.5.jar

     文件     227275  2018-02-01 09:14  RabbitMQHttpApi\lib\httpcore-4.2.4.jar

     文件       2463  2018-03-01 15:36  RabbitMQHttpApi\src\com\test\Test.java

     目录          0  2018-03-01 15:33  RabbitMQHttpApi\bin\com\test

     目录          0  2018-03-01 15:32  RabbitMQHttpApi\src\com\test

     目录          0  2018-03-01 15:33  RabbitMQHttpApi\bin\com

     目录          0  2018-03-01 15:32  RabbitMQHttpApi\src\com

     目录          0  2018-03-01 15:31  RabbitMQHttpApi\.settings

     目录          0  2018-03-01 15:33  RabbitMQHttpApi\bin

     目录          0  2018-03-01 15:32  RabbitMQHttpApi\lib

     目录          0  2018-03-01 15:32  RabbitMQHttpApi\src

     目录          0  2018-03-01 15:31  RabbitMQHttpApi

----------- ---------  ---------- -----  ----

              1026429                    18


评论

共有 条评论