edit-icon download-icon

Create Topic

Last Updated: Dec 29, 2018

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


Topic creation interface is usually used when new Topics are required. For example, to publish a new application, new Topics are required for the business logic.

Topic is globally unique across Regions and must not be duplicate; otherwise, the creation fails, where you need to fix the issue according to the error code.

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. 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 The name of the Topic to be created, which is globally unique and must not be duplicate.
Remark String No A optional note
Appkey String No The key of an application (optional for public cloud users, and required for Tmall Cloud users).
AppName String No An application name (optional for public cloud users).
Order Boolean No Type of message received or sent by the Topic. The value can be true or false.
  • true: Globally ordered message.
  • false: Normal message.
If not set, the default value false is used.

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
  • OnsTopicDelete: deletes a Topic
  • OnsTopicList: views the list of Topics
  • OnsPublishCreate: creates a publishing relation after creating a Topic
  • OnsSubscribeCreate: creates a subscription after creating a Topic


As a reference, this example shows the process of accessing from the end point China East, and creating a Topic with the name of “XXX” in the daily region.

  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. OnsTopicCreateRequest request = new OnsTopicCreateRequest();
  19. request.setAcceptFormat(FormatType.JSON);
  20. request.setTopic("XXXXXXXX");
  21. request.setQps(1000l);
  22. request.setRemark("test");
  23. request.setStatus(0);
  24. /**
  25. *OnsRegionId refers to the resource of the region of MQ required to be accessed by API.
  26. *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.
  27. */
  28. request.setOnsRegionId("daily");
  29. request.setPreventCache(System.currentTimeMillis());
  30. try {
  31. OnsTopicCreateResponse response = client.getAcsResponse(request);
  32. System.out.println(response.getRequestId());
  33. }
  34. catch (ServerException e) {
  35. e.printStackTrace();
  36. }
  37. catch (ClientException e) {
  38. e.printStackTrace();
  39. }
  40. catch (Exception e) {
  41. e.printStackTrace();
  42. }
  43. }
Thank you! We've received your feedback.