edit-icon download-icon

Fetch Topic list

Last Updated: Sep 19, 2018

OnsTopicList interface returns a list of all Topics of the current user.


This interface returns a list of all Topics in the account, and is usually used for generating a list of resources instead of viewing detailed information.

Request parameters

Name Type Required Description
OnsRegionId String Yes The region of the currently queried MQ. It can be obtained with 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 No Specify this to query a specific Topic, or don’t specify to query all Topics.

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 The number 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 ID of the region where the Topic is located. ALIYUN for Alibaba Cloud, and CLOUD for Tmall 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 String null
createTime Long Creation time
updateTime Long Update time
remark String Note
  • OnsTopicCreate: creates a Topic
  • OnsTopicList: views the list of Topics
  • OnsPublishDelete: deletes a publish relation
  • OnsSubscribeDelete: deletes a subscription relation


As a reference, this example shows the process of accessing from the end point China East, and querying the list of 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. OnsTopicListRequest request = new OnsTopicListRequest();
  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.setTopic("XXXXXXXXXXXXX");
  26. try {
  27. OnsTopicListResponse response = IAcsClient.getAcsResponse(request);
  28. List<OnsTopicListResponse.PublishInfoDo> publishInfoDoList=response.getData();
  29. for(OnsTopicListResponse.PublishInfoDo publishInfoDo:publishInfoDoList){
  30. System.out.println(publishInfoDo.getTopic()+" "+ publishInfoDo.getOwner());
  31. }
  32. } catch (ServerException e) {
  33. e.printStackTrace();
  34. } catch (ClientException e) {
  35. e.printStackTrace();
  36. }
  37. }
Thank you! We've received your feedback.