Kafka - Consumer Groups CLI đĨ
Refer back to the theories section for more information on consumer groups.
Description đ
Used to divide partitions among consumers.
Basic Commands đ
-
start a
consumerin aconsumer groupkafka-console-consumer.sh --bootstrap-server <kafka-broker> --topic <topic-name> --group <group-name> -
describe a
consumer groupkafka-consumer-groups.sh --bootstrap-server <kafka-broker> --group <group-name> --describe -
reset a
consumer grouptoearliestoffset to the earliest offsetkafka-consumer-groups.sh --bootstrap-server <kafka-broker> --group <group-name> --reset-offsets --to-earliest --execute --topic <topic-name>- the
--topicflag is needed if theconsumer groupis consuming from multipletopics- you can use
--all-topicsinstead of--topicto reset alltopicsin theconsumer group
- you can use
- the
--executeflag is required to actually reset the offsets
- the
-
shift the
consumer groupoffset bynmessageskafka-consumer-groups.sh --bootstrap-server <kafka-broker> --group <group-name> --reset-offsets --shift-by <number-of-messages> --execute --topic <topic-name>shift-bycan be a negative number to shift the offset backwards bynmessages
Examples đ§Š
- create a
topicwith 3partitionsand 1replication factor-
its necessary to have at least 2
partitionsto make use of aconsumer groupkafka-topics.sh --bootstrap-server localhost:9092 --create --topic first_topic --partitions 3 --replication-factor 1
-
-
start a
consumerin theconsumer groupmy-first-applicationkafka-console-consumer.sh --bootstrap-server localhost:9092 --topic first_topic --group my-first-application-
start a
producerand start producingmessagesto thetopickafka-console-producer.sh --bootstrap-server localhost:9092 --topic first_topic
-
-
start another
consumerpart of the samegroupkafka-console-consumer.sh --bootstrap-server localhost:9092 --topic first_topic --group my-first-application -
start another
consumerpart of a differentgroupfrom beginning, i.e. my-second-applicationkafka-console-consumer.sh --bootstrap-server localhost:9092 --topic first_topic --group my-second-application --from-beginning -
observe the messages being spread
-
describe the
consumer groupkafka-consumer-groups.sh --bootstrap-server localhost:9092 --group my-first-application --describe- output
đ kafka-zero-to-pro ⯠kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group my-first-group GROUP TOPIC PARTITION CURRENT-OFFSET LOG-END-OFFSET LAG CONSUMER-ID HOST CLIENT-ID my-first-group first_topic 0 5 5 0 console-consumer-5d028f33-0549-4826-a719-70b6188d5f52 /127.0.0.1 console-consumer my-first-group first_topic 1 2 2 0 console-consumer-5d028f33-0549-4826-a719-70b6188d5f52 /127.0.0.1 console-consumer my-first-group first_topic 2 1 1 0 console-consumer-c5ff906d-9abc-40d2-83d1-134ead27a552 /127.0.0.1 console-consumer