Reputation: 67
I am new to kafka and am trying to learn on how to implement kafka producer and consumer on the same machine and am not able to understand on how to proceed with it. I want the producer and consumer to run simultaneously. Could someone help me with this.
Upvotes: 0
Views: 3870
Reputation: 154
First you need to download Kafka tar file and extract it. Then go to bin directory and execute following command. Note: producer and consumer command must run in different tab so that in one tab you can produce json and in other you can consume on console.
To create topic:
kafka_2.12-0.11.0.0/bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 3 --topic test_topic
To run Producer on console
kafka-console-producer.sh --broker-list localhost:9092 --topic test_topic
To run consumer on console
kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test_topic --from-beginning
Upvotes: 1
Reputation: 2993
Yes, you can.As both producer will produce on topic.the same topic will be read by consumer. you can try out with this: https://dzone.com/articles/kafka-producer-and-consumer-example
Upvotes: 0