Creates a topic.

Usage notes

You can call this operation to create a topic to meet your business requirements when a new application is released or your business is extended.

Request limit

Each Alibaba Cloud account can call this operation up to 10 times per second. If the number of requests that you send to call this operation within one second reaches the request limit of this operation, new requests fail. This may interrupt your business. For information about the request limit of each operation, see API rate limits.

Authorization

By default, only Alibaba Cloud accounts can call this operation. A Resource Access Management (RAM) user can call this operation to create a topic only after the RAM user is granted the required permissions. The following table describes the permissions that must be granted to a RAM user to call this operation. For information about how to grant permissions, see Policies and examples.

API

Action

Resource in an instance that uses a namespace

Resource in an instance that does not use a namespace

OnsTopicCreate

mq:QueryInstanceBaseInfo

mq:CreateTopic

acs:mq:*:*:{instanceId}%{topic}

acs:mq:*:*:{topic}

Request parameters

Parameter Type Required Example Description
Action String Yes OnsTopicCreate

The operation that you want to perform. Set the value to OnsTopicCreate.

Topic String Yes test

The name of the topic that you want to create. The name must meet following rules:

  • The name must be 3 to 64 characters in length and can contain letters, digits, hyphens (-), and underscores (_).
  • The topic name cannot start with CID or GID because CID and GID are reserved prefixes for group IDs.
  • If the instance in which you want to create the topic uses a namespace, the topic name must be unique in the instance. The topic name cannot be the same as an existing topic name or group ID in the instance. However, the topic name can be the same as a topic name or group ID in another instance that uses a different namespace. For example, Instance A and Instance B use different namespaces. In this case, a topic name in Instance A can be the same as a topic name or group ID in Instance B.
  • If the instance in which you want to create the topic does not use a namespace, the topic name must be globally unique across instances and regions. The topic name cannot be the same as an existing topic name or group ID in Message Queue for Apache RocketMQ within your Alibaba Cloud account.
Note To check whether an instance uses a namespace, log on to the Message Queue for Apache RocketMQ console, go to the Instance Details page, and then view the value of the Namespace field in the Basic Information section.
MessageType Integer Yes 0

The message type. Valid values:

  • 0: normal messages
  • 1: partitionally ordered messages
  • 2: globally ordered messages
  • 4: transactional messages
  • 5: scheduled or delayed messages

For more information about message types, see Overview.

Remark String No Test

The description of the topic.

InstanceId String Yes MQ_INST_188077086902****_BXSuW61e

The ID of the instance in which you want to create the topic.

Response parameters

Parameter Type Example Description
RequestId String B6949B58-223E-4B75-B4FE-7797C15E****

The ID of the request. The system generates a unique ID for each request. You can troubleshoot issues based on the request ID.

Examples

Sample requests

http(s)://ons.cn-zhangjiakou.aliyuncs.com/?Action=OnsTopicCreate
&InstanceId=MQ_INST_188077086902****_BXSuW61e
&MessageType=0
&Topic=test
&<Common request parameters>

Sample success responses

XML format

HTTP/1.1 200 OK
Content-Type:application/xml

<OnsTopicCreateResponse>
<RequestId>B6949B58-223E-4B75-B4FE-7797C15E****</RequestId>
</OnsTopicCreateResponse>

JSON format

HTTP/1.1 200 OK
Content-Type:application/json

{
  "RequestId" : "B6949B58-223E-4B75-B4FE-7797C15E****"
}

Error codes

For a list of error codes, visit the API Error Center.

Create a topic in the console

In the Message Queue for Apache RocketMQ console, you can also create a topic in an instance. For more information, see Manage topics.