edit-icon download-icon

Query Topic status

Last Updated: Sep 19, 2018

OnsTopicGet interface queries the information of a specified Topic. It’s an exact match query.


This interface is used for querying the location of a specified Topic and obtaining information such as its activation status and permission relations. Because it’s an exact match query, the Topic name is required in the input parameter.

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 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 Specify the Topic to be queried

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 category of the Topic, which can be Alibaba Cloud or 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 publishing relation
  • OnsSubscribeDelete: deletes a subscription relation


As a reference, this example shows the process of accessing from the end point China East, querying the Topic “MingduanTest”, and printing the Topic-related information.

  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. OnsTopicGetRequest request = new OnsTopicGetRequest();
  19. request.setAcceptFormat(FormatType.JSON);
  20. request.setTopic("MingduanTest");
  21. /**
  22. *OnsRegionId refers to the resource of the region of MQ required to be accessed by API.
  23. *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.
  24. */
  25. request.setOnsRegionId("daily");
  26. request.setPreventCache(System.currentTimeMillis());
  27. try {
  28. OnsTopicGetResponse response = IAcsClient.getAcsResponse(request);
  29. List<OnsTopicGetResponse.PublishInfoDo> publishInfoDoList=response.getData();
  30. for (OnsTopicGetResponse.PublishInfoDo publishInfoDo:publishInfoDoList){
  31. System.out.println(publishInfoDo.getId()+" "+
  32. publishInfoDo.getChannelId()+" "+
  33. publishInfoDo.getChannelName()+" "+
  34. publishInfoDo.getOnsRegionId()+" "+
  35. publishInfoDo.getRegionName()+" "+
  36. publishInfoDo.getTopic()+" "+
  37. publishInfoDo.getOwner()+" "+
  38. publishInfoDo.getRelation()+" "+
  39. publishInfoDo.getRelationName()+" "+
  40. publishInfoDo.getStatus()+" "+
  41. publishInfoDo.getStatusName()+" "+
  42. publishInfoDo.getAppkey()+" "+
  43. publishInfoDo.getCreateTime()+" "+
  44. publishInfoDo.getUpdateTime()+" "+
  45. publishInfoDo.getRemark());
  46. }
  47. System.out.println(response.getRequestId());
  48. }
  49. catch (ServerException e) {
  50. e.printStackTrace();
  51. }
  52. catch (ClientException e) {
  53. e.printStackTrace();
  54. }
  55. catch (Exception e) {
  56. e.printStackTrace();
  57. }
  58. }
Thank you! We've received your feedback.