Back to Browse

Read and Write data from kafka topic via CLI

837 views
Jun 17, 2022
4:02

kafka tutorial example for beginner #apachekafka #java Sending data to Kafka Topics The role of the producer is to send or write data/messages to the Kafka topics. In this section, we will learn how a producer sends messages to the Kafka topics. There are following steps used to launch a producer: 1. start the zookeeper zookeeper-server-start.bat C:\software\kafka_2.12-2.8.0\config\zookeeper.properties 2. start kafka sever kafka-server-start.bat C:\software\kafka_2.12-2.8.0\config\server.properties 3. write command on console - kafka-console-producer.bat 'broker-list' and a 'topic id' is required to produce a message. It is because a producer must know the id of the topic to which the data is to be written. 4. Try to produce a message to a topic using the command: kafka-console-producer.bat --broker-list 127.0.0.1:9092 --topic provide_topic_name 5. write the message 6. Press 'Ctrl+c' and exist by pressing the 'Y' key Kafka Console Consumer 1: Start the zookeeper as well as the kafka server initially. 2: Type the command: 'kafka-console-consumer' on the command line. This will help the user to read the data from the Kafka topic and output it to the standard outputs. TEXT 'bootstrap-server' is required for the consumer to get connected to the Kafka topics. Also, a 'topic_id' is required to know from which topic the consumer will read the messages. Step3: After knowing all the requirements, try to consume a message from a topic using the command: kafka-console-consumer.bat -bootstrap-server 127.0.0.1:9092 -topic provide_topic_name

Download

0 formats

No download links available.

Read and Write data from kafka topic via CLI | NatokHD