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-
cli
functionalitieskafka-console-consumer.sh
-
consume
messages
from atopic
kafka-console-consumer.sh --bootstrap-server <kafka-broker> --topic <topic-name>
- the consumer will start consuming from the
end
of thetopic
by default -
to test this, you can use the
producer
to sendmessages
to thetopic
and then use theconsumer
to consume themessages
from thetopic
-
create a
topic
-
create a
consumer
to consumemessages
from thetopic
-
create a
producer
to sendmessages
to thetopic
-
view the
messages
consumed by theconsumer
in theterminal
-
-
view the next
message
in thetopic
kafka-console-producer.sh --bootstrap-server <kafka-broker> --topic <topic-name>
- the consumer will start consuming from the
-
consume
messages
from atopic
at thebeginning
kafka-console-consumer.sh --bootstrap-server <kafka-broker> --topic <topic-name> --from-beginning
-
display key, values and timestamps of
messages
consumedkafka-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
messages
from atopic
kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic first_topic
-
consume
messages
from atopic
kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic first_topic --from-beginning
-
display key, values and timestamps of
messages
consumedkafka-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
producer
andconsumer
-
prodcuer
producesmessages
to 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
-
consumer
consumesmessages
from 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
-