edit-icon download-icon

Query trace by message key

Last Updated: Apr 08, 2018

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

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

Usage

This interface can be used to create a query task when the business party has recorded the Message Key of a message and needs to query the delivery trace of this message with the key. 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
MsgKey String Yes Message Key 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
  • OnsTraceQueryByMsgId: precisely queries the message trace by Message ID.
  • OnsTraceGetResult: retrieves trace information by query Task ID.

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. OnsTraceQueryByMsgKeyRequest request = new OnsTraceQueryByMsgKeyRequest();
  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.setMsgKey("XXXXX");
  28. request.setBeginTime(System.currentTimeMillis()-1000*3600*24);
  29. request.setEndTime(System.currentTimeMillis());
  30. try {
  31. OnsTraceQueryByMsgKeyResponse 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.