BSR Tutorials

Kafka - Create Test Producer and Consumer

You need to make sure both zookeeper and Kafka server are running before executing the commands. Also, please create the Kafka topic before test the producer and consumer.
You can use built-in producer and consumer to test the message flow in Kafka topics.
Please follow the below steps to test it.

  1. Ensure the Kafka topic exists, if not create a new topic using the following command.
    Kafka-topics.bat -create -zookeeper 127.0.0.1:2181 --replication-factor 1 -partitions 1 --topic smstest

  2. To start a producer, use the following command and enter.
    Kafka-console-producer.bat –broker-list 127.0.0.1:9092 –topic smstest

  3. To start a consumer, use the following command and enter.
    Kafka-console-consumer.bat –bootstrap-server 127.0.0.1:9092 –topic smstest

    Now, you can send the message from Producer and check Consumer receives the same message.

  4. You may need to change the server.properties file with following config setting.
    Uncomment the following line
    listeners=PLAINTEXT://:9092
    and change this to
    listeners=PLAINTEXT://127.0.0.1:9092

    The, run the Kafka server using the command.
    .\bin\windows\kafka-server-start.bat .\config\server.properties
    Otherwise, you may get the “Connection to node 0 could not be established” error message.

Tutorial #1: Kafka - Introduction
Tutorial #4: Kafka - Use Cases
Tutorial #5: Kafka - Clients
Tutorial #8: Kafka - Create test producer and consumer (current page)