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.
To consume a message from a Pulsar topic, we need to provide the mandatory parameters:
./bin/pulsar-client consume persistent://my-tenant/my-namespace/my-topic -s "my-subscription"
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:
./bin/pulsar-client consume persistent://my-tenant/my-namespace/my-topic -s "my-subscription" -n 0
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:
./bin/pulsar-client consume persistent://my-tenant/my-namespace/my-topic -s "my-subscription" -p "Earliest" -n 0