In Message Queue for Apache RocketMQ, a topic is a primary category for messages. Message Queue for Apache RocketMQ uses the publish-subscribe model, where producers publish messages to topics and consumers subscribe to those topics to receive them. This article describes how to create, delete, update, and view topics in the Message Queue for Apache RocketMQ console.
Usage notes
-
A topic is isolated within an instance and cannot be used across different instances. For example, a topic created in instance A cannot be used in instance B.
-
A topic's message type must match the messages it will handle. For example, if you create a topic to send and receive normal messages, its message type must be set to Normal Message. You cannot use it for other message types, such as partitioned ordered messages or transactional messages. Otherwise, problems may occur, such as losing scheduled messages during node replacement or instance migration.
Billing
Message Queue for Apache RocketMQ charges a resource usage fee for each topic, even if the topic is not used. We recommend deleting unused topics. For more information, see Messaging pricing details and Enterprise Platinum Edition billing.
Topic naming conventions
-
A topic name must be 3 to 64 characters long and can contain only letters, digits, hyphens (-), and underscores (_).
-
If the topic's instance has a namespace, its name must be unique within that instance and cannot match an existing topic name or group ID. Names can be duplicated across different instances. For example, a topic in instance A can have the same name as a topic or a group ID in instance B.
-
If the topic's instance does not have a namespace, its name must be globally unique across all instances and regions and cannot match any existing topic name or group ID.
To check whether an instance has a namespace, go to the Instance Details page in the Message Queue for Apache RocketMQ console and view the Basic Information section.
Create a topic
Log on to the ApsaraMQ for RocketMQ console. In the left-side navigation pane, click Instances.
In the top navigation bar, select a region, such as China (Hangzhou). On the Instances page, click the name of the instance that you want to manage.
-
In the navigation pane on the left, click Topics. In the upper-left corner of the page, click Create Topic.
-
In the Create Topic panel, enter a Name and Description, select a Message Type for the topic, and click OK.
ImportantA topic can handle only the message type specified during its creation. For example, if you create a topic with the message type set to Normal Message, you can use it only to send and receive normal messages. You cannot use this topic for ordered messages. For more information, see Message types.
The Name must be 3 to 64 characters long and can contain only letters, digits, hyphens (-), and underscores (_). The Commodity Type is automatically set to pay-as-you-go. Message Type includes four options: Normal Message, Transactional Message, Partitioned Ordered Message, and Scheduled/Delayed Message.
Delete a topic
After a topic is deleted, its associated producers and consumers immediately stop working. The topic metadata and message data are also deleted and cannot be restored. Proceed with caution.
-
On the Instances page, click the name of the target instance. In the navigation pane on the left, click Topics.
-
In the topic list, find the topic that you want to delete. In the Actions column, click More and select Delete from the drop-down menu.
-
In the confirmation dialog box, click OK.
Update a topic
-
On the Instances page, click the name of the target instance. In the navigation pane on the left, click Topics.
-
In the topic list, find the topic that you want to update. In the Actions column, click Details to open the Topic Details page.
-
In the Basic Information section, click Edit next to Topic Description. Enter the new description and click OK.
View a topic
-
On the Instances page, click the name of the target instance. In the navigation pane on the left, click Topics.
-
In the topic list, click the topic's name, or click Details in its Actions column.
Related APIs
You can also use the following API operations to manage topics:
-
Create a topic: OnsTopicCreate
-
Delete a topic: OnsTopicDelete
-
Query a list of topics: OnsTopicList
-
Query the total number of messages in a topic and its last update time: OnsTopicStatus
-
Query the subscriptions of a topic: OnsTopicSubDetail