Pulsar Academy

Pulsar Producer CLI Tutorial

Learn how to produce messages to Pulsar using the Pulsar Client CLI.

Introduction

Producers in Pulsar are used to publish data to topics. Using the Pulsar Client CLI, you can read data from standard input and publish it to Pulsar. Before you run the commands below, make sure you have started Pulsar.

How to produce a message into a Pulsar topic using the CLI?

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

  • Persistence & Tenant name & Namespace name & Topic name
  • Message body
./bin/pulsar-client produce persistent://my-tenant/my-namespace/my-topic -m "Hello World!"

How to produce a message with key using the Pulsar Client CLI?

By default, messages are sent with a null key. To produce a keyed message to a Pulsar topic, we need to provide the mandatory parameters:

  • Persistence & Tenant name & Namespace name & Topic name
  • Message key
  • Message body
./bin/pulsar-client produce persistent://my-tenant/my-namespace/my-topic -k "My Message Key" -m "Hello World!"

How to produce messages from a file into a Pulsar topic using the CLI?

To produce messages from a file to a Pulsar topic, we need to provide the mandatory parameters:

  • Persistence & Tenant name & Namespace name & Topic name
  • File path (Note: Make sure every message is on a new line)
./bin/pulsar-client produce persistent://my-tenant/my-namespace/my-topic -f input-file.txt

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.