閱讀898 返回首頁    go 英雄聯盟


查詢消費堆積__消費管理相關接口_Open API_消息隊列 MQ-阿裏雲

本文介紹 OnsConsumerAccumulate 接口,用於查詢指定訂閱組的消費堆積情況,可以獲取到訂閱組當前未消費的消息數以及大概的延遲時間。

1. 使用場景

消費堆積查詢一般在生產環境中需要關注訂閱組消費進度時使用,用於粗略判斷消息消費情況和延遲情況。

2. 請求參數列表

名稱 類型 是否必須 描述
OnsRegionId String 當前查詢 MQ 所在區域,可以通過 ONSRegionList 方法獲取
OnsPlatform String 該請求來源,默認是從 POP 平台
PreventCache Long 用於 CSRF 校驗,設置為係統當前時間即可
ConsumerId String 需要查詢的消費端 CID
Detail Boolean 是否查詢詳細信息,默認為否

3. 返回參數列表

名稱 類型 描述
RequestId String 為公共參數,每個請求獨一無二
HelpUrl String 幫助鏈接
Data Data 指定 Consumer 的消費堆積情況

Data 數據結構

成員 類型 描述
OnLine Boolean 當前消費者是否在線
TotalDiff Long 當前 Consumer ID 訂閱的所有 Topic 的消息總堆積數
ConsumeTps Float 當前消費 TPS
LastTimestamp Long 最後更新時刻
DelayTime Long 延遲時間
DetailInTopicList List(OnsConsumerAccumulateResponse.Data.DetailInTopicDo) 各個 Topic 具體情況

DetailInTopicList 數據結構

成員 類型 描述
Topic String Topic 名稱
TotalDiff Long 當前 Topic 的消費堆積
LastTimestamp Long 最後更新時刻
DelayTime Long 當前 Topic 的消費延遲時間

4. 相關 API

  • OnsConsumerStatus:消費者狀態詳情查詢
  • OnsConsumerConnection:消費者連接查詢
  • OnsResetOffset:消費清理堆積

5. 使用示例

調用示例

  1. public static void main(String []args) {
  2. String regionId = "cn-hangzhou";
  3. String accessKey = "XXXXXXXXXXXXXXXXX";
  4. String secretKey = "XXXXXXXXXXXXXXXXX";
  5. String endPointName ="cn-hangzhou";
  6. String productName ="Ons";
  7. String domain ="ons.cn-hangzhou.aliyuncs.com";
  8. /**
  9. *根據自己需要訪問的區域選擇Region,並設置對應的接入點
  10. */
  11. try {
  12. DefaultProfile.addEndpoint(endPointName,regionId,productName,domain);
  13. } catch (ClientException e) {
  14. e.printStackTrace();
  15. }
  16. IClientProfile profile= DefaultProfile.getProfile(regionId,accessKey,secretKey);
  17. IAcsClient iAcsClient= new DefaultAcsClient(profile);
  18. OnsConsumerAccumulateRequest request = new OnsConsumerAccumulateRequest();
  19. // request.setCluster("taobaodaily");
  20. /**
  21. *ONSRegionId是指你需要API訪問MQ哪個區域的資源.
  22. *該值必須要根據OnsRegionList方法獲取的列表來選擇和配置,因為OnsRegionId是變動的,不能夠寫固定值
  23. */
  24. request.setOnsRegionId("daily");
  25. request.setPreventCache(System.currentTimeMillis());
  26. request.setAcceptFormat(FormatType.JSON);
  27. request.setDetail(true);
  28. request.setConsumerId("RTDSQ_1013_GROUP");
  29. try {
  30. OnsConsumerAccumulateResponse response=iAcsClient.getAcsResponse(request);
  31. OnsConsumerAccumulateResponse.Data data =response.getData();
  32. System.out.println(data.getOnline()+" "+data.getTotalDiff()+" "+data.getConsumeTps()+" "
  33. +data.getDelayTime()+" "+data.getLastTimestamp());
  34. for (OnsConsumerAccumulateResponse.Data.DetailInTopicDo detailInTopicDo:data.getDetailInTopicList()){
  35. System.out.println(detailInTopicDo.getTopic()+" "
  36. +detailInTopicDo.getTotalDiff()+" "
  37. +detailInTopicDo.getLastTimestamp()+" "+detailInTopicDo.getDelayTime());
  38. }
  39. } catch (ServerException e) {
  40. e.printStackTrace();
  41. } catch (ClientException e) {
  42. e.printStackTrace();
  43. }
  44. }

最後更新:2016-11-23 18:55:40

  上一篇:go 查詢 Topic 當前位點__Topic 相關接口_Open API_消息隊列 MQ-阿裏雲
  下一篇:go 查詢消費狀態__消費管理相關接口_Open API_消息隊列 MQ-阿裏雲