Skip to content
Latchkey

pulsar-client produce and consume

pulsar-client produce <topic> -m <msg> publishes to Pulsar and pulsar-client consume <topic> -s <sub> -n <count> reads back, a shell smoke test for a broker.

pulsar-client is the message-level companion to pulsar-admin. It proves that a topic accepts writes and delivers reads without writing a client program.

What it does

pulsar-client produce sends one or more messages (-m repeated, or -n copies) to a topic. consume attaches a subscription (-s) and reads up to -n messages. It uses the binary protocol on the broker service URL (default pulsar://localhost:6650), separate from the admin URL.

Common usage

Terminal
pulsar-client produce persistent://public/default/orders \
  -m 'hello' -n 1
# consume: a subscription name is required
pulsar-client consume persistent://public/default/orders \
  -s test-sub -n 1
# subscribe from the earliest message
pulsar-client consume persistent://public/default/orders \
  -s test-sub -n 1 --subscription-position Earliest

Options

FlagWhat it does
produce <topic> -m <msg>Message body to send
-n <n>Number of messages to produce or consume
consume <topic> -s <sub>Subscription name (required to consume)
--subscription-position Earliest|LatestWhere a new subscription starts
--service-url <url>Broker binary service URL (pulsar://)

In CI

consume needs a subscription name (-s) and reads only messages that arrive after the subscription is created, unless you pass --subscription-position Earliest. Bound the read with -n so the command exits instead of waiting forever. The service URL uses pulsar:// on 6650, not the admin http:// on 8080.

Common errors in CI

"Topic does not exist" (or a partitioned-metadata lookup failure) means the topic or its namespace was not created; provision it with pulsar-admin first. "Could not connect to broker" or "Connection refused" on 6650 means the broker binary port is not ready. A consume that returns nothing usually forgot --subscription-position Earliest for pre-existing messages.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →