admin
2022-04-16 04f09e52ffd4681bdfd85e51acd3da0d1280c3d3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package com.yeshi.buwan.job.domain;
 
import com.tencentcloudapi.clb.v20180317.ClbClient;
import com.tencentcloudapi.clb.v20180317.models.DescribeLoadBalancersRequest;
import com.tencentcloudapi.clb.v20180317.models.DescribeLoadBalancersResponse;
import com.tencentcloudapi.clb.v20180317.models.LoadBalancer;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
 
/**
 * @author hxh
 * @title: TencentCloudSLBUtil
 * @description: 腾讯云负载均衡
 * api:https://console.cloud.tencent.com/api/explorer?Product=clb&Version=2018-03-17&Action=DescribeLoadBalancers&SignVersion=
 * @date 2022/4/16 13:33
 */
public class TencentCloudCLBUtil {
 
    private final static String SECRET_ID = "AKIDTlpgJhLjOozvd6QI2XnpfGbgV4NQJk25";
    private final static String SECRET_KEY = "xhCSUHo55oHUQ6XicFcmfIgspX0EEzWo";
 
 
    /**
     * @return com.tencentcloudapi.clb.v20180317.models.LoadBalancer[]
     * @author hxh
     * @description 获取负载均衡的列表,IsBlock表示是否封堵
     * @date 13:44 2022/4/16
     * @param: name
     **/
    public static LoadBalancer[] getCLBList(String name) throws TencentCloudSDKException {
        // 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey,此处还需注意密钥对的保密
        // 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取
        Credential cred = new Credential(SECRET_ID, SECRET_KEY);
        // 实例化一个http选项,可选的,没有特殊需求可以跳过
        HttpProfile httpProfile = new HttpProfile();
        httpProfile.setEndpoint("clb.tencentcloudapi.com");
        // 实例化一个client选项,可选的,没有特殊需求可以跳过
        ClientProfile clientProfile = new ClientProfile();
        clientProfile.setHttpProfile(httpProfile);
        // 实例化要请求产品的client对象,clientProfile是可选的
        ClbClient client = new ClbClient(cred, "ap-guangzhou", clientProfile);
        // 实例化一个请求对象,每个接口都会对应一个request对象
        DescribeLoadBalancersRequest req = new DescribeLoadBalancersRequest();
        req.setLoadBalancerName(name);
        // 返回的resp是一个DescribeLoadBalancersResponse的实例,与请求对象对应
        DescribeLoadBalancersResponse resp = client.DescribeLoadBalancers(req);
 
        return resp.getLoadBalancerSet();
    }
 
 
    public static void main(String[] args) throws TencentCloudSDKException {
        LoadBalancer[] bs = TencentCloudCLBUtil.getCLBList("布丸-备用");
        System.out.println(bs);
    }
 
 
}