Overview
Topics are the channels through which messages are sent and received in Pulsar. The Topics API provides comprehensive management capabilities for both persistent and non-persistent topics, including partitioning, subscriptions, and topic-level policies. Base Path:/admin/v2/persistent (for persistent topics)
List Topics
Get all topics in a namespace.Path Parameters
The tenant name
The namespace name
Query Parameters
Specific bundle to query
Include system topics in the list
Example
Response Example
List Partitioned Topics
Get all partitioned topics in a namespace.Example
Create Non-Partitioned Topic
Create a new non-partitioned topic.Path Parameters
The tenant name
The namespace name
The topic name
Query Parameters
Whether this broker is authoritative
Request Body
Key-value pairs for topic metadata
Example
Response Codes
| Code | Description |
|---|---|
| 204 | Topic created successfully |
| 307 | Current broker doesn’t serve this namespace |
| 401 | Don’t have permission |
| 403 | Don’t have admin permission |
| 404 | Tenant or namespace doesn’t exist |
| 409 | Topic already exists |
Create Partitioned Topic
Create a partitioned topic with a specified number of partitions.Path Parameters
The tenant name
The namespace name
The topic name
Request Body
Number of partitions (must be > 0)
Query Parameters
Create topic only on local cluster
Example
Response Codes
| Code | Description |
|---|---|
| 204 | Partitioned topic created successfully |
| 401 | Don’t have permission |
| 403 | Don’t have admin permission |
| 404 | Tenant or namespace doesn’t exist |
| 406 | Number of partitions exceeds maximum |
| 409 | Topic already exists |
Update Partitions
Increase the number of partitions for an existing partitioned topic.Request Body
New number of partitions (must be greater than current)
Example
Topic Permissions
Get Permissions
Retrieve permissions for a topic.Grant Permission
Grant permissions to a role on a topic.Path Parameters
The role name
Request Body
Array of actions: “produce”, “consume”, “functions”
Example
Revoke Permission
Revoke permissions from a role on a topic.Example
Topic Policies
Offload Policies
Configure automatic offloading to long-term storage.Set Offload Policies
Request Body
Size threshold for offloading
Age threshold for offloading
Storage driver: “aws-s3”, “google-cloud-storage”, “filesystem”
Example
Get Offload Policies
Query Parameters
Get effective policies (including inherited)
Delete Offload Policies
Max Unacked Messages
Control the maximum number of unacknowledged messages.Set Max Unacked Messages on Consumer
Request Body
Maximum number of unacked messages per consumer
Example
Get Max Unacked Messages on Consumer
Delete Max Unacked Messages Policy
Delayed Delivery
Configure delayed message delivery.Set Delayed Delivery Policies
Request Body
Tick time for delayed delivery in milliseconds
Whether delayed delivery is enabled
Example
Get Delayed Delivery Policies
Inactive Topic Policies
Configure automatic cleanup of inactive topics.Set Inactive Topic Policies
Request Body
Delete mode: “delete_when_no_subscriptions” or “delete_when_subscriptions_caught_up”
Maximum inactive duration before deletion
Example
Best Practices
Topic Naming
- Use descriptive names that reflect the data type
- Follow a consistent naming convention
- Avoid special characters except hyphens and underscores
- Consider using hierarchical names with separators
Partitioning Strategy
- Use partitioned topics for high-throughput scenarios
- Start with 1-2 partitions per broker core
- Monitor partition load and adjust as needed
- Plan partition count growth carefully (can only increase)
Policy Configuration
- Set offload policies for cost-effective storage
- Configure inactive topic cleanup to free resources
- Use max unacked messages to prevent consumer overload
- Enable delayed delivery for scheduled message processing
Performance Optimization
- Use appropriate partition counts for parallelism
- Configure batching for better throughput
- Set message TTL to prevent unbounded growth
- Monitor topic statistics regularly
Related Resources
Namespaces API
Configure namespace-level policies
Schemas API
Manage topic schemas