|
1 | 1 | package com.qcloud.cmq; |
2 | 2 |
|
| 3 | +import com.qcloud.cmq.entity.CmqConfig; |
3 | 4 | import com.qcloud.cmq.entity.CmqResponse; |
4 | 5 | import com.qcloud.cmq.json.JSONArray; |
5 | 6 | import com.qcloud.cmq.json.JSONObject; |
6 | 7 |
|
7 | 8 | import java.util.ArrayList; |
8 | 9 | import java.util.List; |
9 | 10 | import java.util.TreeMap; |
| 11 | +import com.tencentcloudapi.common.Credential; |
| 12 | +import com.tencentcloudapi.common.exception.TencentCloudSDKException; |
| 13 | +import com.tencentcloudapi.common.profile.ClientProfile; |
| 14 | +import com.tencentcloudapi.common.profile.HttpProfile; |
| 15 | +import com.tencentcloudapi.tdmq.v20200217.TdmqClient; |
| 16 | +import com.tencentcloudapi.tdmq.v20200217.models.CmqQueue; |
| 17 | +import com.tencentcloudapi.tdmq.v20200217.models.DescribeCmqQueueDetailRequest; |
| 18 | +import com.tencentcloudapi.tdmq.v20200217.models.DescribeCmqQueueDetailResponse; |
10 | 19 |
|
11 | 20 | /** |
12 | 21 | * Queue class. |
@@ -64,30 +73,44 @@ public void setQueueAttributes(QueueMeta meta) throws Exception { |
64 | 73 | * |
65 | 74 | * @return 返回的队列属性参数 |
66 | 75 | */ |
67 | | - public QueueMeta getQueueAttributes() throws Exception { |
68 | | - TreeMap<String, String> param = new TreeMap<String, String>(); |
69 | | - |
70 | | - param.put("queueName", this.queueName); |
71 | | - String result = this.client.call("GetQueueAttributes", param); |
72 | | - JSONObject jsonObj = new JSONObject(result); |
73 | | - CMQTool.checkResult(result); |
74 | | - |
| 76 | + public QueueMeta getQueueAttributes() { |
75 | 77 | QueueMeta meta = new QueueMeta(); |
76 | | - meta.maxMsgHeapNum = jsonObj.getInt("maxMsgHeapNum"); |
77 | | - meta.pollingWaitSeconds = jsonObj.getInt("pollingWaitSeconds"); |
78 | | - meta.visibilityTimeout = jsonObj.getInt("visibilityTimeout"); |
79 | | - meta.maxMsgSize = jsonObj.getInt("maxMsgSize"); |
80 | | - meta.msgRetentionSeconds = jsonObj.getInt("msgRetentionSeconds"); |
81 | | - meta.createTime = jsonObj.getInt("createTime"); |
82 | | - meta.lastModifyTime = jsonObj.getInt("lastModifyTime"); |
83 | | - meta.activeMsgNum = jsonObj.getInt("activeMsgNum"); |
84 | | - meta.inactiveMsgNum = jsonObj.getInt("inactiveMsgNum"); |
85 | | - meta.rewindmsgNum = jsonObj.getInt("rewindMsgNum"); |
86 | | - meta.minMsgTime = jsonObj.getInt("minMsgTime"); |
87 | | - meta.delayMsgNum = jsonObj.getInt("delayMsgNum"); |
88 | | - meta.rewindSeconds = jsonObj.getInt("rewindSeconds"); |
89 | | - |
90 | | - |
| 78 | + try{ |
| 79 | + CmqConfig cmqConfig = client.getCmqConfig(); |
| 80 | + Credential cred = new Credential(cmqConfig.getSecretId(), cmqConfig.getSecretKey()); |
| 81 | + String endPoint = cmqConfig.getEndpoint(); |
| 82 | + String region = CMQTool.convertRegion(endPoint); |
| 83 | + HttpProfile httpProfile = new HttpProfile(); |
| 84 | + httpProfile.setEndpoint(cmqConfig.getManagerEndpoint()); |
| 85 | + ClientProfile clientProfile = new ClientProfile(); |
| 86 | + clientProfile.setHttpProfile(httpProfile); |
| 87 | + TdmqClient client = new TdmqClient(cred, region, clientProfile); |
| 88 | + DescribeCmqQueueDetailRequest req = new DescribeCmqQueueDetailRequest(); |
| 89 | + req.setQueueName(this.queueName); |
| 90 | + DescribeCmqQueueDetailResponse resp = client.DescribeCmqQueueDetail(req); |
| 91 | + CmqQueue cmqQueue = resp.getQueueDescribe(); |
| 92 | + meta.maxMsgHeapNum = cmqQueue.getMaxMsgHeapNum().intValue(); |
| 93 | + meta.pollingWaitSeconds = cmqQueue.getPollingWaitSeconds().intValue(); |
| 94 | + meta.visibilityTimeout = cmqQueue.getVisibilityTimeout().intValue(); |
| 95 | + meta.maxMsgSize = cmqQueue.getMaxMsgSize().intValue(); |
| 96 | + meta.msgRetentionSeconds = cmqQueue.getMsgRetentionSeconds().intValue(); |
| 97 | + meta.createTime = (int)(cmqQueue.getCreateTime()/1000); |
| 98 | + meta.lastModifyTime = (int)(cmqQueue.getLastModifyTime()/1000); |
| 99 | + meta.activeMsgNum = cmqQueue.getActiveMsgNum().intValue(); |
| 100 | + meta.inactiveMsgNum = cmqQueue.getInactiveMsgNum().intValue(); |
| 101 | + if (null != cmqQueue.getRewindMsgNum()) { |
| 102 | + meta.rewindmsgNum = cmqQueue.getRewindMsgNum().intValue(); |
| 103 | + } |
| 104 | + if (null != cmqQueue.getMinMsgTime()) { |
| 105 | + meta.minMsgTime = cmqQueue.getMinMsgTime().intValue(); |
| 106 | + } |
| 107 | + if (null != cmqQueue.getDelayMsgNum()) { |
| 108 | + meta.delayMsgNum = cmqQueue.getDelayMsgNum().intValue(); |
| 109 | + } |
| 110 | + meta.rewindSeconds = cmqQueue.getRewindSeconds().intValue(); |
| 111 | + } catch (TencentCloudSDKException e) { |
| 112 | + System.out.println(e.toString()); |
| 113 | + } |
91 | 114 | return meta; |
92 | 115 | } |
93 | 116 |
|
|
0 commit comments