edit-icon download-icon

Query message trace

Last Updated: Apr 08, 2018

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

Description

OnsMessageTrack interface determines if a message with the target MsgId has been consumed.

Usage

MessageTrack interface is usually used for determining if a specified message has been consumed, with the MsgId of a single message as the query criterion. Note that because this interface is implemented based on the internal offset system of MQ, the result is credible in most cases. However, if the user has reset the offset or cleared the messages, then the result can be incorrect.

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.
Topic String Yes Topic of the message
MsgId String Yes ID of a message

Response parameters

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

MessageTrack data structure

Name Type Description
ConsumerGroup String The name of a consumption cluster
TrackType String Current status
ExceptionDesc String Exception description
  • OnsMessageGetByMsgId: precisely queries a message by MsgId

Example

  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 you will access, and set the corresponding access point.
  10. */
  11. try {
  12. DefaultProfile.addEndpoint(endPointNameregionIdproductNamedomain);
  13. } catch (ClientException e) {
  14. e.printStackTrace();
  15. }
  16. IClientProfile profile= DefaultProfile.getProfile(regionIdaccessKeysecretKey);
  17. IAcsClient iAcsClient= new DefaultAcsClient(profile);
  18. OnsMessageTraceRequest request = new OnsMessageTraceRequest();
  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.setTopic("MingduanTest");
  27. request.setMsgId("0A91883700001F90000001BF4723CB3E");
  28. try {
  29. OnsMessageTraceResponse response=iAcsClient.getAcsResponse(request);
  30. List<OnsMessageTraceResponse.MessageTrack> trackList =response.getData();
  31. for (OnsMessageTraceResponse.MessageTrack track:trackList){
  32. System.out.println(track.getConsumerGroup()+" "+track.getTrackType()+" "+track.getExceptionDesc());
  33. }
  34. } catch (ServerException e) {
  35. e.printStackTrace();
  36. } catch (ClientException e) {
  37. e.printStackTrace();
  38. }
  39. }
Thank you! We've received your feedback.