Kafka - Producers CLI đ
Refer back to the theories section for more information on producers.
Description đ
Produce data for a topic. This is the most common way to write data to Kafka. It reads data from standard input and sends it to the Kafka cluster.
Basic Commands đ
-
produce data to a
topickafka-console-producer.sh --bootstrap-server <kafka-broker> --topic <topic-name> -
produce data to a
topicwith propertieskafka-console-producer.sh --bootstrap-server <kafka-broker> --topic <topic-name> --producer-property <property-name>=<property-value> -
produce data to a
topicwith properties and akeykafka-console-producer.sh --bootstrap-server <kafka-broker> --topic <topic-name> --property parse.key=true --property key.separator=<key-value-separator>
Examples đ§Š
-
produce data to a
topickafka-console-producer.sh --bootstrap-server localhost:9092 --topic first_topic >Hello World >My name is Guerrero >I love learning new thingsCtrl + Cis used to exit the producer
-
produce data to a
topicwith propertieskafka-console-producer.sh --bootstrap-server localhost:9092 --topic first_topic --producer-property acks=all > some message that is acked > just for fun > fun learning!
-
produce to a
topicthat does not existkafka-console-producer.sh --bootstrap-server localhost:9092 --topic new_topic > hello world!-
by default,
Kafkawill create atopicif it does not exist -
the new topic only has one partition
kafka-topics.sh --bootstrap-server localhost:9092 --listkafka-topics.sh --bootstrap-server localhost:9092 --topic new_topic --describe-
output
đ kafka-zero-to-pro â kafka-topics.sh --bootstrap-server localhost:9092 --topic new_topic --describe Topic: new_topic TopicId: gKHMWVz-Q9a51Zs0wezdNg PartitionCount: 1 ReplicationFactor: 1 Configs: segment.bytes=1073741824 Topic: new_topic Partition: 0 Leader: 1 Replicas: 1 Isr: 1- by default,
Kafkawill create atopicwith a singlepartitionand areplication factorof one-
to edit the default settings, edit
config/server.propertiesorconfig/kraft/server.propertiesnum.partitions=3 -
produce to another non existing topic
kafka-console-producer.sh --bootstrap-server localhost:9092 --topic new_topic_2 > hello world again! -
this time the topic has 3 partitions
kafka-topics.sh --bootstrap-server localhost:9092 --topic new_topic_2 --describeTopic: new_topic_2 TopicId: 5Q3Z2ZzvQXq2Z2Z2Z2Z2Zg PartitionCount: 3 ReplicationFactor: 1 Configs: segment.bytes=1073741824 Topic: new_topic_2 Partition: 0 Leader: 1 Replicas: 1 Isr: 1 Topic: new_topic_2 Partition: 1 Leader: 1 Replicas: 1 Isr: 1 Topic: new_topic_2 Partition: 2 Leader: 1 Replicas: 1 Isr: 1- even though
Kafkaprovides this functionality, its best to createtopicsbefore producing to them!
- even though
-
- by default,
-
-
-
produce to a
topicwith a keykafka-console-producer --bootstrap-server localhost:9092 --topic first_topic --property parse.key=true --property key.separator=: >example key:example value >name:Guerrero