edit-icon download-icon

Query trace by message ID

Last Updated: Oct 17, 2018

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

OnsTraceQueryByMsgId interface creates a trace query task with the transferred Topic and Message ID and returns the Task ID of the query task.


This interface can be used to create a query task when the business party has recorded the Message ID of a message and needs to query the delivery trace of this message with the Message ID. After the Task ID is returned by the interface, the OnsTraceGetResult interface can be used for retrieving the query result with the transferred Task ID.

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.
Topic String Yes Topic of the message to be queried
MsgId String Yes Message ID of the message to be queried
BeginTime Long Yes The start time of the query time range
EndTime Long Yes The end time of the query time range

Response parameters

Name Type Description
RequestId String A public parameter unique for each request
HelpUrl String A help link
QueryId String Task ID of the query task; the OnsTraceGetResult interface is called to retrieve the detailed result by the ID
  • OnsTraceQueryByMsgKey: fuzzily queries the message trace by Message Key.
  • OnsTraceGetResult: retrieves trace information by query Task ID.


  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. OnsTraceQueryByMsgIdRequest request = new OnsTraceQueryByMsgIdRequest();
  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("XXXXX");
  27. request.setMsgId("XXXXX");
  28. request.setBeginTime(System.currentTimeMillis()-1000*3600*24);
  29. request.setEndTime(System.currentTimeMillis());
  30. try {
  31. OnsTraceQueryByMsgIdResponse response = iAcsClient.getAcsResponse(request);
  32. System.out.print(response.getQueryId());
  33. } catch (ServerException e) {
  34. e.printStackTrace();
  35. } catch (ClientException e) {
  36. e.printStackTrace();
  37. }
  38. }
Thank you! We've received your feedback.