阅读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-阿里云