edit-icon download-icon

Reset consumer offset

Last Updated: Oct 09, 2018

This interface is exclusive for MQ Platinum edition users. For more information, go to Platinum Edition Purchase Page.


This interface resets the consumer offset of the current Consumer ID to the specified time stamp according to the Consumer ID specified by the user. It’s used for clearing accumulated messages or tracing back consumption. It provides two methods: one is to clear all messages, and the other is to clear the consumption progress to the specified time.

Request parameters

Name Type Required Description
OnsRegionId String Yes The region where the queried MQ is currently located. It can be obtained through the OnsRegionList method.
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 name of the Topic of which the offset needs to be reset
Type Integer Yes Set to0 to clear all messages, or set to 1 to clear the consumption progress to the specified time.
ResetTimestamp Long false It resets the offset to the specified time stamp. Only effective when Type is set to 1.

Response parameters

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


  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. *Select Region based on the region where you are located, and set the corresponding access point.
  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. OnsConsumerResetOffsetRequest request = new OnsConsumerResetOffsetRequest();
  19. /**
  20. *OnsRegionId refers to the resource of the region of MQ required to be accessed by API.
  21. *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.
  22. */
  23. request.setOnsRegionId("daily");
  24. request.setPreventCache(System.currentTimeMillis());
  25. request.setAcceptFormat(FormatType.JSON);
  26. request.setConsumerId("CID_Mingduan");
  27. request.setTopic("MingduanTest");
  28. request.setType(1);
  29. request.setResetTimestamp(System.currentTimeMillis());
  30. try {
  31. OnsConsumerResetOffsetResponse response=iAcsClient.getAcsResponse(request);
  32. System.out.println(response.getRequestId());
  33. } catch (ServerException e) {
  34. e.printStackTrace();
  35. } catch (ClientException e) {
  36. e.printStackTrace();
  37. }
  38. }
Thank you! We've received your feedback.