edit-icon download-icon

Query Topic details

Last Updated: Sep 19, 2018

OnsTopicSeacrh interface returns a list of all Topics in the specified account according to the search criteria.


This interface is used for querying Topics without knowing Topic names, and returns a list of all Topics. An exact match query can then be performed with the OnsTopicGet interface for a specified Topic.

Request parameters

Name Type Required Description
OnsRegionId String Yes The region of the currently queried MQ. It can be obtained with the OnsRegionList method. For more information, see Terms.
OnsPlatform String No The request sources from the POP platform by default.
PreventCache Long Yes It’s used for CSRF verification. Set it to the current system time.
Search String Yes Input search criteria such as Topic field or appname field.

Response parameters

Name Type Description
RequestId String A public parameter unique for each request
HelpUrl String A help link
Data List(PublishInfoDo) Returns a list of all published Topics

PublishInfoDo data structure

Member Type Description
id Long Information No. of the Topic
channelId Integer The ID of the region where the Topic is located. 0 for Alibaba Cloud, and 1 for Tmall Cloud.
channelName String The name of the region where the Topic is located, including ALIYUN, CLOUD…
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; Alibaba Cloud’s UID
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”, 1 for “frozen”, and 2 for “paused”)
statusName String The alias of the current status(“in service”, “frozen”, and “paused”
appkey Integer null
createTime Long Creation time
updateTime Long Update time
remark String Note information
  • OnsTopicCreate: creates a Topic
  • OnsTopicList: views the list of Topics
  • OnsPublishDelete: deletes a publishing relation
  • OnsSubscribeDelete: deletes a subscription relation


As a reference, this example shows the process of accessing from the end point China East, and querying all Topics of the current user.

  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. OnsTopicSearchRequest request = new OnsTopicSearchRequest();
  19. request.setAcceptFormat(FormatType.JSON);
  20. /**
  21. *OnsRegionId refers to the resource of the region of MQ required to be accessed by API.
  22. *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.
  23. */
  24. request.setOnsRegionId("daily");
  25. request.setPreventCache(System.currentTimeMillis());
  26. request.setSearch("JODIE_TEST_28dd");
  27. try {
  28. OnsTopicSearchResponse response = IAcsClient.getAcsResponse(request);
  29. List<OnsTopicSearchResponse.PublishInfoDo> publishInfoDoList=response.getData();
  30. for(OnsTopicSearchResponse.PublishInfoDo publishInfoDo:publishInfoDoList){
  31. System.out.println(publishInfoDo.getTopic()+" "+publishInfoDo.getOwner());
  32. }
  33. System.out.println(response.getRequestId());
  34. } catch (ClientException e) {
  35. e.printStackTrace();
  36. }
  37. catch (Exception e) {
  38. e.printStackTrace();
  39. }
  40. }
Thank you! We've received your feedback.