Kafka: Message Producer
Go to the Kafka bin folder before running any of the command
$ cd ~/kafka_2.11-1.1.0/bin
➠
Publish Messages in Kafka
- Each line entered after running producer will be new message. Producer can be terminated using (ctrl+c)from publishing more messages.
./kafka-console-producer.sh --broker-list localhost:9092 --topic kafka_test_topic
Kafka Message 1
Kafka Message 2
Kafka Message 3
Kafka Message 4
Kafka Message 5
- Publishing message using file, keep all the message (1 message per line) in any file (InsertWithFile.txt) and pass it in the producer command as shown below.
./kafka-console-producer.sh --broker-list localhost:9092 --topic kafka_test_topic_withpartition < ~/InsertWithFile.txt
File 'InsertWithFile.txt' Contents
Kafka Topic 2 Message 1
Kafka Topic 2 Message 2
Kafka Topic 2 Message 3
Kafka Topic 2 Message 4
Kafka Topic 2 Message 5
➠
Purging Message in Kafka