Search in sources :

Example 1 with CmqConfig

use of com.qcloud.cmq.entity.CmqConfig 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)

Example 2 with CmqConfig

use of com.qcloud.cmq.entity.CmqConfig in project cmq-java-sdk by tencentyun.

the class Queue method getQueueAttributes.

/**
 * 获取队列属性
 *
 * @return 返回的队列属性参数
 */
public QueueMeta getQueueAttributes() {
    QueueMeta meta = new QueueMeta();
    try {
        CmqConfig cmqConfig = client.getCmqConfig();
        Credential cred = new Credential(cmqConfig.getSecretId(), cmqConfig.getSecretKey());
        String endPoint = cmqConfig.getEndpoint();
        String region = CMQTool.convertRegion(endPoint);
        HttpProfile httpProfile = new HttpProfile();
        httpProfile.setEndpoint(cmqConfig.getManagerEndpoint());
        ClientProfile clientProfile = new ClientProfile();
        clientProfile.setHttpProfile(httpProfile);
        TdmqClient client = new TdmqClient(cred, region, clientProfile);
        DescribeCmqQueueDetailRequest req = new DescribeCmqQueueDetailRequest();
        req.setQueueName(this.queueName);
        DescribeCmqQueueDetailResponse resp = client.DescribeCmqQueueDetail(req);
        CmqQueue cmqQueue = resp.getQueueDescribe();
        meta.maxMsgHeapNum = cmqQueue.getMaxMsgHeapNum().intValue();
        meta.pollingWaitSeconds = cmqQueue.getPollingWaitSeconds().intValue();
        meta.visibilityTimeout = cmqQueue.getVisibilityTimeout().intValue();
        meta.maxMsgSize = cmqQueue.getMaxMsgSize().intValue();
        meta.msgRetentionSeconds = cmqQueue.getMsgRetentionSeconds().intValue();
        meta.createTime = (int) (cmqQueue.getCreateTime() / 1000);
        meta.lastModifyTime = (int) (cmqQueue.getLastModifyTime() / 1000);
        meta.activeMsgNum = cmqQueue.getActiveMsgNum().intValue();
        meta.inactiveMsgNum = cmqQueue.getInactiveMsgNum().intValue();
        if (null != cmqQueue.getRewindMsgNum()) {
            meta.rewindmsgNum = cmqQueue.getRewindMsgNum().intValue();
        }
        if (null != cmqQueue.getMinMsgTime()) {
            meta.minMsgTime = cmqQueue.getMinMsgTime().intValue();
        }
        if (null != cmqQueue.getDelayMsgNum()) {
            meta.delayMsgNum = cmqQueue.getDelayMsgNum().intValue();
        }
        meta.rewindSeconds = cmqQueue.getRewindSeconds().intValue();
    } catch (TencentCloudSDKException e) {
        System.out.println(e.toString());
    }
    return meta;
}
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) HttpProfile(com.tencentcloudapi.common.profile.HttpProfile) DescribeCmqQueueDetailRequest(com.tencentcloudapi.tdmq.v20200217.models.DescribeCmqQueueDetailRequest) DescribeCmqQueueDetailResponse(com.tencentcloudapi.tdmq.v20200217.models.DescribeCmqQueueDetailResponse) CmqQueue(com.tencentcloudapi.tdmq.v20200217.models.CmqQueue)

Example 3 with CmqConfig

use of com.qcloud.cmq.entity.CmqConfig in project cmq-java-sdk by tencentyun.

the class TopicTest method initConfig.

@Before
public void initConfig() {
    cmqConfig = new CmqConfig();
    cmqConfig.setEndpoint("");
    cmqConfig.setSecretId("");
    cmqConfig.setSecretKey("");
    cmqConfig.setConnectTimeout(10000);
    cmqConfig.setReadTimeout(10000);
    cmqConfig.setMethod("POST");
    cmqConfig.setMaxIdleConnections(1);
    account = new Account(cmqConfig);
}
Also used : CmqConfig(com.qcloud.cmq.entity.CmqConfig) Before(org.junit.Before)

Example 4 with CmqConfig

use of com.qcloud.cmq.entity.CmqConfig in project jeesuite-libs by vakinge.

the class CMQManager method doInit.

private void doInit() {
    queueName = MQContext.getGroupName();
    CmqConfig config = ResourceUtils.getBean("jeesuite.amqp.cmq.", CmqConfig.class);
    Validate.notBlank(config.getEndpoint(), "config[mq.cmq.endpoint] not found");
    Validate.notBlank(config.getSecretId(), "config[mq.cmq.secretId] not found");
    Validate.notBlank(config.getSecretKey(), "config[mq.cmq.secretKey] not found");
    config.setAlwaysPrintResultLog(false);
    config.setPrintSlow(false);
    this.account = new Account(config);
    logger.info("init CMQ Account OK -> endpoint:{}", config.getEndpoint());
}
Also used : Account(com.qcloud.cmq.Account) CmqConfig(com.qcloud.cmq.entity.CmqConfig)

Example 5 with CmqConfig

use of com.qcloud.cmq.entity.CmqConfig in project jeesuite-libs by vakinge.

the class CMQManager method doInit.

private void doInit() {
    queueName = MQContext.getGroupName();
    CmqConfig config = ResourceUtils.getBean("mendmix.amqp.cmq.", CmqConfig.class);
    Validate.notBlank(config.getEndpoint(), "config[mq.cmq.endpoint] not found");
    Validate.notBlank(config.getSecretId(), "config[mq.cmq.secretId] not found");
    Validate.notBlank(config.getSecretKey(), "config[mq.cmq.secretKey] not found");
    config.setAlwaysPrintResultLog(false);
    config.setPrintSlow(false);
    this.account = new Account(config);
    logger.info("init CMQ Account OK -> endpoint:{}", config.getEndpoint());
}
Also used : Account(com.qcloud.cmq.Account) CmqConfig(com.qcloud.cmq.entity.CmqConfig)

Aggregations

CmqConfig (com.qcloud.cmq.entity.CmqConfig)6 Account (com.qcloud.cmq.Account)2 Credential (com.tencentcloudapi.common.Credential)2 TencentCloudSDKException (com.tencentcloudapi.common.exception.TencentCloudSDKException)2 ClientProfile (com.tencentcloudapi.common.profile.ClientProfile)2 HttpProfile (com.tencentcloudapi.common.profile.HttpProfile)2 TdmqClient (com.tencentcloudapi.tdmq.v20200217.TdmqClient)2 CmqQueue (com.tencentcloudapi.tdmq.v20200217.models.CmqQueue)2 Before (org.junit.Before)2 DescribeCmqQueueDetailRequest (com.tencentcloudapi.tdmq.v20200217.models.DescribeCmqQueueDetailRequest)1 DescribeCmqQueueDetailResponse (com.tencentcloudapi.tdmq.v20200217.models.DescribeCmqQueueDetailResponse)1 DescribeCmqQueuesRequest (com.tencentcloudapi.tdmq.v20200217.models.DescribeCmqQueuesRequest)1 DescribeCmqQueuesResponse (com.tencentcloudapi.tdmq.v20200217.models.DescribeCmqQueuesResponse)1