Updated on 2025-12-18 GMT+08:00

Creating a Topic or Deleting Topics in Batches

Function

This API is used to create a topic or delete topics in batches.

URI

POST /v2/{project_id}/instances/{instance_id}/topics

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Definition

Project ID. For details about how to obtain it, see Obtaining a Project ID.

Constraints

N/A

Range

N/A

Default Value

N/A

instance_id

Yes

String

Definition

Instance ID. You can call the API for querying all instances to obtain the instance ID. The instance ID is in the response body.

Constraints

N/A

Range

N/A

Default Value

N/A

Table 2 Query Parameters

Parameter

Mandatory

Type

Description

action

No

String

Definition

This parameter is used to delete topics in batches. If it is not set, a topic will be created.

Constraints

N/A

Range

  • delete: batch deletion

  • Left blank: topic creation

Default Value

N/A

Request Parameters

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

name

No

String

Definition

Topic name.

Constraints

Enter 3 to 64 characters. Use only letters, digits, percent (%), vertical bars (|), hyphens (-), and underscores (_).

Mandatory for topic creation.

Range

N/A

Default Value

N/A

brokers

No

Array of strings

Associated broker. This parameter is mandatory only for RocketMQ 4.8.0 instances.

queue_num

No

Number

Total number of queues. The range is 1–50.

queues

No

Array of queues objects

Queue. This parameter is mandatory only for RocketMQ 4.8.0 instances.

permission

No

String

Permission. This parameter is mandatory only for RocketMQ 4.8.0 instances.

Options:

  • pub (publish)

  • sub (subscribe)

  • all (publish + subscribe)

message_type

No

String

Message type (This parameter is mandatory only for RocketMQ 5.x instances).

Options:

  • NORMAL (normal messages)

  • FIFO (ordered messages)

  • DELAY (scheduled messages)

  • TRANSACTION (transactional messages)

topics

No

Array of strings

Topic list. This parameter is used when topics are deleted in batches.

Table 4 queues

Parameter

Mandatory

Type

Description

broker

No

String

Associated brokers.

queue_num

No

Number

Number of queues. The value ranges from 1 to 50.

Response Parameters

Status code: 200

Table 5 Response body parameters

Parameter

Type

Description

id

String

Topic name.

job_id

String

Job ID for deleting topics.

Example Requests

  • For RocketMQ 4.8.0 instances: Creating a topic associated with broker-0 with 3 queues

    POST https://{endpoint}/v2/{project_id}/instances/{instance_id}/topics
    
    {
      "name" : "topic-test",
      "permission" : "all",
      "queues" : [ {
        "broker" : "broker-0",
        "queue_num" : 3
      } ]
    }
  • Deleting topics of a RocketMQ 5.x instance in a batch

    POST https://{endpoint}/v2/{project_id}/instances/{instance_id}/topics?action=delete
    
    {
      "topics" : [ "topic01", "topic02" ]
    }

Example Responses

Status code: 200

Topic created.

  • Successfully created the topic

    {
      "id" : "topic-test"
    }
  • Successfully deleted topics in a batch

    {
      "job_id" : "8abfa7b299f0497c0199f0dc0a9a092b"
    }

Status Codes

Status Code

Description

200

Topic created.

Error Codes

See Error Codes.