Search in sources :

Example 1 with DescribeCmqQueuesResponse

use of com.tencentcloudapi.tdmq.v20200217.models.DescribeCmqQueuesResponse in project cmq-java-sdk by tencentyun.

the class Account method listQueue.

/**
 * list queue
 *
 * @param searchWord String
 * @param offset     int
 * @param limit      int
 * @param queueList  List<String>
 * @return totalCount int
 * @throws Exception
 * @throws CMQClientException
 * @throws CMQServerException
 */
public int listQueue(String searchWord, int offset, int limit, List<String> queueList) {
    try {
        CmqConfig cmqConfig = client.getCmqConfig();
        Credential cred = new Credential(cmqConfig.getSecretId(), cmqConfig.getSecretKey());
        String endPoint = cmqConfig.getEndpoint();
        String region = CMQTool.convertRegion(endPoint);
        DescribeCmqQueuesRequest req = new DescribeCmqQueuesRequest();
        if (offset > 0) {
            req.setOffset((long) offset);
        }
        if (limit > 0) {
            req.setLimit((long) limit);
        }
        if (null != searchWord && !"".equals(searchWord)) {
            req.setQueueName(searchWord);
        }
        HttpProfile httpProfile = new HttpProfile();
        httpProfile.setEndpoint(cmqConfig.getManagerEndpoint());
        ClientProfile clientProfile = new ClientProfile();
        clientProfile.setHttpProfile(httpProfile);
        TdmqClient client = new TdmqClient(cred, region, clientProfile);
        DescribeCmqQueuesResponse resp = client.DescribeCmqQueues(req);
        CmqQueue[] cmqQueues = resp.getQueueList();
        int totalCount = resp.getTotalCount().intValue();
        if (cmqQueues.length > 0) {
            for (CmqQueue queue : resp.getQueueList()) {
                queueList.add(queue.getQueueName());
            }
        }
        return totalCount;
    } catch (TencentCloudSDKException e) {
        System.out.println(e.toString());
    }
    return 0;
}
Also used : Credential(com.tencentcloudapi.common.Credential) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) TdmqClient(com.tencentcloudapi.tdmq.v20200217.TdmqClient) CmqConfig(com.qcloud.cmq.entity.CmqConfig) ClientProfile(com.tencentcloudapi.common.profile.ClientProfile) DescribeCmqQueuesRequest(com.tencentcloudapi.tdmq.v20200217.models.DescribeCmqQueuesRequest) HttpProfile(com.tencentcloudapi.common.profile.HttpProfile) DescribeCmqQueuesResponse(com.tencentcloudapi.tdmq.v20200217.models.DescribeCmqQueuesResponse) CmqQueue(com.tencentcloudapi.tdmq.v20200217.models.CmqQueue)

Aggregations

CmqConfig (com.qcloud.cmq.entity.CmqConfig)1 Credential (com.tencentcloudapi.common.Credential)1 TencentCloudSDKException (com.tencentcloudapi.common.exception.TencentCloudSDKException)1 ClientProfile (com.tencentcloudapi.common.profile.ClientProfile)1 HttpProfile (com.tencentcloudapi.common.profile.HttpProfile)1 TdmqClient (com.tencentcloudapi.tdmq.v20200217.TdmqClient)1 CmqQueue (com.tencentcloudapi.tdmq.v20200217.models.CmqQueue)1 DescribeCmqQueuesRequest (com.tencentcloudapi.tdmq.v20200217.models.DescribeCmqQueuesRequest)1 DescribeCmqQueuesResponse (com.tencentcloudapi.tdmq.v20200217.models.DescribeCmqQueuesResponse)1