Kafka - Consumers CLI đŊī¸
Refer back to the theories section for more information on consumers.
Description đ
The Kafka cli uses consumers for consuming messages from Kafka topics.
Basic Commands đ
-
get consumers-
clifunctionalitieskafka-console-consumer.sh -
consume
messagesfrom atopickafka-console-consumer.sh --bootstrap-server <kafka-broker> --topic <topic-name>- the consumer will start consuming from the
endof thetopicby default -
to test this, you can use the
producerto sendmessagesto thetopicand then use theconsumerto consume themessagesfrom thetopic-
create a
topic -
create a
consumerto consumemessagesfrom thetopic -
create a
producerto sendmessagesto thetopic -
view the
messagesconsumed by theconsumerin theterminal
-
-
view the next
messagein thetopickafka-console-producer.sh --bootstrap-server <kafka-broker> --topic <topic-name>
- the consumer will start consuming from the
-
consume
messagesfrom atopicat thebeginningkafka-console-consumer.sh --bootstrap-server <kafka-broker> --topic <topic-name> --from-beginning -
display key, values and timestamps of
messagesconsumedkafka-console-consumer.sh --bootstrap-server <kafka-broker> --topic <topic-name> --formatter kafka.tools.DefaultMessageFormatter --property print.key=true --property print.value=true --property print.timestamp=true --from-beginning
Examples đ§Š
-
consume
messagesfrom atopickafka-console-consumer.sh --bootstrap-server localhost:9092 --topic first_topic -
consume
messagesfrom atopickafka-console-consumer.sh --bootstrap-server localhost:9092 --topic first_topic --from-beginning -
display key, values and timestamps of
messagesconsumedkafka-console-consumer.sh --bootstrap-server localhost:9092 --topic first_topic --formatter kafka.tools.DefaultMessageFormatter --property print.key=true --property print.value=true --property print.timestamp=true -
sample output from final example using
producerandconsumer-
prodcuerproducesmessagesto thetopicđ kafka-zero-to-pro ⯠kafka-console-producer.sh --bootstrap-server localhost:9092 --topic first_topic --property parse.key=true --property key.separator=: >hello:world >im:guerrero >i:love learning -
consumerconsumesmessagesfrom thetopicđ kafka-zero-to-pro ⯠kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic first_topic --formatter kafka.tools.DefaultMessageFormatter --property print.key=true --property print.value=true --property print.timestamp=true CreateTime:1667959647470 hello world CreateTime:1667959656726 im guerrero CreateTime:1667959665180 i love learning
-