edit-icon download-icon

Query consumption progress

Last Updated: Jan 30, 2018

OnsConsumerTimeSpan interface queries the latest message time stamp of the Topic subscribed by the current Consumer ID, and the latest consumption time stamp.


This interface can be used for querying the latest and earliest time of a Topic’s messages on the server, and querying the latest consumption time of the consumer. It’s usually used in combination with the ConsumeAccumulate interface for getting a rough idea of the consumption progress.

Request parameters

Name Type Required Description
OnsRegionId String Yes It specifies the region to be queried. The value is obtained through the OnsRegionList interface.
OnsPlatform String No The source of the request, which by default is POP platform.
PreventCache Long Yes It’s used for CSRF verification. Set it to the current system time.
ConsumerId String Yes The consumer CID to be queried
Topic String Yes The Topic of which the consumption to be queried

Response parameters

Name Type Description
RequestId String A public parameter unique for each request
HelpUrl String A help link
Data Data Query result

Data structure

Member Type Description
Topic String The name of the queried Topic.
MinTimeStamp Long The time of latest message stored in the Topic.
MaxTimeStamp Long The time of oldest message stored in the Topic.
ConsumeTimeStamp Long The time when the group last consumed the Topic.
  • OnsConsumerAccumulate: queries the consumption accumulation
  • OnsConsumerStatus: queries the consumer details
  • OnsConsumerResetOffset: resets the offset and clears messages


  1. public static void main(String []args) {
  2. String regionId = "cn-hangzhou";
  3. String regionId = "cn-hangzhou";
  4. String accessKey = "XXXXXXXXXXXXXXXXX";
  5. String secretKey = "XXXXXXXXXXXXXXXXX";
  6. String endPointName ="cn-hangzhou";
  7. String productName ="Ons";
  8. String domain ="ons.cn-hangzhou.aliyuncs.com";
  9. /**
  10. *Select Region based on the region you will access, and set the corresponding access point.
  11. */
  12. try {
  13. DefaultProfile.addEndpoint(endPointNameregionIdproductNamedomain);
  14. } catch (ClientException e) {
  15. e.printStackTrace();
  16. }
  17. IClientProfile profile= DefaultProfile.getProfile(regionIdaccessKeysecretKey);
  18. IAcsClient iAcsClient= new DefaultAcsClient(profile);
  19. OnsConsumerTimeSpanRequest request = new OnsConsumerTimeSpanRequest();
  20. /**
  21. *OnsRegionId refers to the resource of the region of MQ required to be accessed by API.
  22. *This value must be selected and configured by the list obtained through the OnsRegionList method because OnsRegionId is changing, and cannot be written as a fixed value.
  23. */
  24. request.setOnsRegionId("daily");
  25. request.setPreventCache(System.currentTimeMillis());
  26. request.setAcceptFormat(FormatType.JSON);
  27. request.setConsumerId("CID_Mingduan");
  28. request.setTopic("MingduanTest12");
  29. try {
  30. OnsConsumerTimeSpanResponse response=iAcsClient.getAcsResponse(request);
  31. OnsConsumerTimeSpanResponse.Data data =response.getData();
  32. System.out.println(data.getTopic()+"\n"+
  33. data.getConsumeTimeStamp()+"\n"+
  34. data.getMaxTimeStamp()+"\n"+
  35. data.getMinTimeStamp());
  36. } catch (ServerException e) {
  37. e.printStackTrace();
  38. } catch (ClientException e) {
  39. e.printStackTrace();
  40. }
  41. }
Thank you! We've received your feedback.