Pulsar Academy

Pulsar Consumer CLI Tutorial

Learn how to consume messages from Pulsar using the Pulsar Client CLI.

Introduction

Consumers in Pulsar use a subscription in order to receive messages from topics. Using the Pulsar Client CLI, you can read data from Pulsar and print it to standard output. Before you run the commands below, make sure you have started Pulsar.

How to consume messages from a Pulsar topic using the CLI?

To consume a message from a Pulsar topic, we need to provide the mandatory parameters:

  • Persistence & Tenant name & Namespace name & Topic name
  • Subscription name
./bin/pulsar-client consume persistent://my-tenant/my-namespace/my-topic -s "my-subscription"

How to keep consuming from a Pulsar topic using the CLI?

By default, only a single message is consumed. To keep the consumer running and receiving messages from a Pulsar topic, we need to provide the mandatory parameters:

  • Persistence & Tenant name & Namespace name & Topic name
  • Subscription name
  • Number of messages (Note: to keep consuming we set it to 0)
./bin/pulsar-client consume persistent://my-tenant/my-namespace/my-topic -s "my-subscription" -n 0

How to consume all messages from the beginning of a Pulsar topic using the CLI?

By default, the subscription starts at the latest point in time. To set the subscription to the bstart of a topic and consume all of its messages, we need to provide the mandatory parameters:

  • Persistence & Tenant name & Namespace name & Topic name
  • Subscription name
  • Subscription position
  • Number of messages (Note: to keep consuming we set it to 0)
./bin/pulsar-client consume persistent://my-tenant/my-namespace/my-topic -s "my-subscription" -p "Earliest" -n 0

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.