edit-icon download-icon

Delete Topic

Last Updated: Oct 17, 2018

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


OnsTopicDelete interface deletes a specified Topic in the account.

This interface is used for recycling resources when, for example, the application is offline. When deleting a Topic, the MQ backend slows down due to recycling resources, so it’s not recommended to re-create the Topic immediately after deleting it. If Topic deletion fails, please process it according to the error code.

NOTE: deleting a Topic also removes all of its connections with Producer IDs/Consumer IDs. Call this API with caution.

Restrictions on primary accounts and sub-accounts

This interface is exclusively available for primary accounts by default, and cannot be used by RAM sub-accounts unless they are granted related permission.

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 deleted.

Response parameters

Name Type Description
RequestId String A public parameter unique for each request, used for troubleshooting and identifying issues.
HelpUrl String A help link
  • OnsTopicCreate: creates a Topic
  • OnsTopicList: views the list of Topics
  • OnsPublishDelete: deletes a publishing relation
  • OnsSubscribeDelete: deletes a subscription


As a reference, this example shows the process of accessing from the end point China East, and deleting a Topic with the name of “Mingduan_67dd”.

  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. OnsTopicDeleteRequest request =new OnsTopicDeleteRequest();
  19. request.setCluster("taobaodaily");
  20. request.setPreventCache(System.currentTimeMillis());
  21. /**
  22. *OnsRegionId refers to the particular region of MQ set 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.setTopic("Mingduan_67dd");
  27. try {
  28. OnsTopicDeleteResponse response = client.getAcsResponse(request);
  29. System.out.println(response.getRequestId());
  30. }
  31. catch (ServerException e) {
  32. e.printStackTrace();
  33. }
  34. catch (ClientException e) {
  35. e.printStackTrace();
  36. }
  37. catch (Exception e) {
  38. e.printStackTrace();
  39. }
  40. }
Thank you! We've received your feedback.