Pulsar Academy

Pulsar Topics CLI Tutorial

Learn how to manage Topics using the Pulsar Admin CLI.

Introduction

Topics in Pulsar are used as a channel through which messages are produced and consumed. There are two main types of topics:

  • Non-partitioned Topics: Only served by a single broker, limiting the maximum throughput
  • Partitioned Topics: Served by multiple brokers, allowing for higher throughput

Before you run the commands below, make sure you have started Pulsar.

How to create a Pulsar topic?

To create a new non-partitioned topic in Pulsar, we need to provide the mandatory parameters:

  • Persistence & Tenant name & Namespace name & Topic name
./bin/pulsar-admin topics create persistent://my-tenant/my-namespace/my-topic

How to create a partitioned Pulsar topic?

To create a new partitioned topic in Pulsar, we need to provide the mandatory parameters:

  • Persistence & Tenant name & Namespace name & Topic name
  • Number of partitions (Note: the partitions can only be increased, not decreased later)
./bin/pulsar-admin topics create-partitioned-topic persistent://my-tenant/my-namespace/my-partitioned-topic --partitions 5

How to list Pulsar topics?

To list all topics under a namespace in Pulsar, we need to provide the mandatory parameters:

  • Tenant name & Namespace name
./bin/pulsar-admin topics list my-tenant/my-namespace

How to list only partitioned Pulsar topics?

To list only the partitioned topics under a namespace in Pulsar, we need to provide the mandatory parameters:

  • Tenant name & Namespace name
./bin/pulsar-admin topics list-partitioned-topics my-tenant/my-namespace

How to get Pulsar topic statistics?

To get statistics information about a topic in Pulsar, we need to provide the mandatory parameters:

  • Persistence & Tenant name & Namespace name & Topic Name
# For non-partitioned topics
./bin/pulsar-admin topics stats persistent://my-tenant/my-namespace/my-topic

# For partitioned topics
./bin/pulsar-admin topics partitioned-stats persistent://my-tenant/my-namespace/my-partitioned-topic

How to delete a Pulsar topic?

To delete a topic in Pulsar, we need to provide the mandatory parameters:

  • Persistence & Tenant name & Namespace name & Topic name
# For non-partitioned topics
./bin/pulsar-admin topics delete persistent://my-tenant/my-namespace/my-topic

# For partitioned topics
./bin/pulsar-admin topics delete-partitioned-topic persistent://my-tenant/my-namespace/my-partitioned-topic

Table of Contents

Let's stay in touch

Get notified of new developments or blogposts.
Checkmark icon
You've joined the mailing list!
Oops! Something went wrong while submitting the form.