Produce and consume messages
In this tutorial, we will:
- Configure the Pulsar client
- Create a subscription
- Create a producer
- Send test messages
- Verify the results
Prerequisites​
Produce and consume messages​
-
In the
${PULSAR_HOME}/conf/client.conf
file, replacewebServiceUrl
andbrokerServiceUrl
with your service URL. -
Create a subscription to consume messages from
apache/pulsar/test-topic
.bin/pulsar-client consume -s sub apache/pulsar/test-topic -n 0
-
In a new terminal, create a producer and send 10 messages to test-topic.
bin/pulsar-client produce apache/pulsar/test-topic -m "---------hello apache pulsar-------" -n 10
-
Verify the results.
----- got message -----
---------hello apache pulsar-------
----- got message -----
---------hello apache pulsar-------
----- got message -----
---------hello apache pulsar-------
----- got message -----
---------hello apache pulsar-------
----- got message -----
---------hello apache pulsar-------
----- got message -----
---------hello apache pulsar-------
----- got message -----
---------hello apache pulsar-------
----- got message -----
---------hello apache pulsar-------
----- got message -----
---------hello apache pulsar-------
----- got message -----
---------hello apache pulsar-------
Output from the producer side shows the messages have been produced successfully:
18:15:15.489 [main] INFO org.apache.pulsar.client.cli.PulsarClientTool - 10 messages successfully produced.