edit-icon download-icon

Query PID

Last Updated: Jun 21, 2018

This topic introduces the OnsPublishSearch interface that queries publishing relations according to the search criteria.

Usage

When there are too many PIDs under a user account to present at once, you can call the OnsPublishSearch interface to search for publishing relations that match the keyword. The presented data format is consistent with that of the OnsPublishGet interface.

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.
Search String Yes A keyword for search, which can be Topic or PID.

Response parameters

Name Type Description
RequestId String A public parameter unique for each request
HelpUrl String A help link
Data List(PublishInfoDo) A set of query results

PublishInfoDo data structure

Member Type Description
id Long ID of the publishing information in the database
channelId Integer The ID of the region where the Topic is located, including 0-ALIYUN, 1-CLOUD, 2, 3, and 4
channelName String Number of the current status
onsRegionId Long The ID of the region where the Topic is located; obtained through the OnsRegionList method.
regionName String The name of the region where the Topic is located.
Topic String The Topic name
owner String The number of the Topic owner
relation Integer Numbers of all relations. 1 for the owner, 2 for “publish”, 4 for “subscribe”, and 6 for “publish and subscribe”.
relationName String Names of all relations such as the owner, “subscribe”, “publish”, and “publish and subscribe”.
status Integer Number of the current status. 0 for In Service.
statusName String The alias of the current status, which can be In Service.
appkey Integer null
createTime Long Creation time
updateTime Long Update time
remark String An optional note
  • OnsPublishDelete: deletes a publishing relation
  • OnsPublishGet: queries a publishing relation
  • OnsPublishCreate: creates a publishing relation

Example

This example is to search for information related to a PID in the daily region by taking PID_Mingduan as the search criterion and print the result.

This example shows the process of querying the PIDs with PID_Mingduan as the search keyword in the daily region, and printing the result.

  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. OnsPublishSearchRequest request = new OnsPublishSearchRequest();
  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.setSearch("PID_Mingduan");
  27. try {
  28. OnsPublishSearchResponse response=iAcsClient.getAcsResponse(request);
  29. List<OnsPublishSearchResponse.PublishInfoDo> publishInfoDoList =response.getData();
  30. for (OnsPublishSearchResponse.PublishInfoDo publishInfoDo:publishInfoDoList){
  31. System.out.println(publishInfoDo.getId()+" "+
  32. publishInfoDo.getChannelId()+" "+
  33. publishInfoDo.getChannelName()+" "+
  34. publishInfoDo.getOnsRegionId()+" "+
  35. publishInfoDo.getRegionName()+" "+
  36. publishInfoDo.getOwner()+" "+
  37. publishInfoDo.getProducerId()+" "+
  38. publishInfoDo.getTopic()+" "+
  39. publishInfoDo.getStatus()+" "+
  40. publishInfoDo.getStatusName()+" "+
  41. publishInfoDo.getCreateTime()+" "+
  42. publishInfoDo.getUpdateTime());
  43. }
  44. } catch (ServerException e) {
  45. e.printStackTrace();
  46. } catch (ClientException e) {
  47. e.printStackTrace();
  48. }
  49. }
Thank you! We've received your feedback.