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.
To produce a message to a Pulsar topic, we need to provide the mandatory parameters:
./bin/pulsar-client produce persistent://my-tenant/my-namespace/my-topic -m "Hello World!"
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:
./bin/pulsar-client produce persistent://my-tenant/my-namespace/my-topic -k "My Message Key" -m "Hello World!"
To produce messages from a file to a Pulsar topic, we need to provide the mandatory parameters:
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