Updated on 2026-04-30 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

Definition

Associated broker.

Constraints

This parameter is mandatory only for RocketMQ 4.8.0 instances. This parameter is valid only when parameter queues is left blank.

Range

N/A

Default Value

N/A

queue_num

No

Number

Definition

Total number of queues.

Constraints

This parameter is mandatory only for RocketMQ 4.8.0 instances. This parameter is valid only when parameter queues is left blank.

Range

1–50

Default Value

4

queues

No

Array of queues objects

Definition

Queue.

Constraints

This parameter is required only for RocketMQ 4.8.0 instances.

Range

N/A

Default Value

N/A

permission

No

String

Definition

Permission.

Constraints

This parameter is required only for RocketMQ 4.8.0 instances.

Range

  • pub: publish

  • sub: subscribe

  • all: publish and subscribe

Default Value

all

message_type

No

String

Definition

Message type.

Constraints

This parameter is required only for RocketMQ 5.x instances.

Range

  • NORMAL: normal messages.

  • FIFO: ordered messages.

  • DELAY: scheduled messages.

  • TRANSACTION: transactional messages.

Default Value

NORMAL

topics

No

Array of strings

Definition

Topic list.

Constraints

Mandatory for batch topic deletion.

Range

N/A

Default Value

N/A

Table 4 queues

Parameter

Mandatory

Type

Description

broker

No

String

Associated brokers.

queue_num

No

Number

Definition

Number of queues.

Constraints

N/A

Range

1–50

Default Value

3

Response Parameters

Status code: 200

Table 5 Response body parameters

Parameter

Type

Description

id

String

Definition

Topic name.

Constraints

N/A

Range

N/A

Default Value

N/A

job_id

String

Definition

ID of the topic deletion task.

Constraints

N/A

Range

N/A

Default Value

N/A

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.