A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/java/apache-kafka-create-consumers-in-a-consumer-group-using-cli/ below:

Apache Kafka - Create Consumers in a Consumer Group using CLI

Apache Kafka - Create Consumers in a Consumer Group using CLI

Last Updated : 23 Jul, 2025

In Apache Kafka, a consumer group is a set of consumers that work together to consume a topic. A set of partitions is given to each group member consumer to choose from.  When a consumer in the group finishes consuming a message from its assigned partition, it sends a message to the Kafka broker to commit the offset (the position of the consumer in the partition). In this way, the consumer group is able to track its progress through the partition and pick up where it left off if a consumer fails or the group needs to scale up or down. This makes it easy to build fault-tolerant, scalable, and distributed applications with Kafka. Here are some key points to remember about consumer groups in Kafka:

Example of Creating a Consumer Group

It is not possible to have more consumers in a group than there are partitions in the Kafka topic. Therefore, you must first create a Kafka topic with a sufficient number of partitions. In the example, the topic has 3 partitions

kafka-topics.sh --bootstrap-server localhost:9092 --topic my-topic --create --partitions 3 --replication-factor 1

Next, start a consumer in a consumer group called 'my-first-application'.

kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic my-topic --group my-first-application 

In a new terminal window, start a second consumer in the 'my-first-application' consumer group using the same command as the first consumer.

kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic my-topic --group my-first-application 

Open a new terminal window and start a third consumer in the 'my-first-application' consumer group.

kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic my-topic --group my-first-application 

Note: The same command is being used to create multiple consumers in the same consumer group.

Each consumer in the 'my-first-application' consumer group will be assigned a partition. Send a few string messages to the topic.

Produce some messages to my-topic.

Each consumer will only display the messages produced on the partition that has been assigned to it.

Kafka Consumer group demo.

If you stop one of the consumers, the messages will be automatically sent to the remaining consumers because consumer groups automatically perform a consumer rebalance when a consumer is stopped

Stop all the consumers, and then when a consumer in the group is restarted, it will start consuming messages from the latest committed offsets and will only process messages that have been produced since the consumer was stopped.

Here are a few things to remember:

Here are some advanced parameters that you can use when creating a Kafka consumer group:

Here is an example of using some of these options to create a consumer group:

kafka-console-consumer --bootstrap-server localhost:9092 --topic my-topic --group my-first-application --from-beginning --auto-offset-reset earliest --property print.key=true --property key.separator=,

This will create a consumer group called my-first-application that consumes from the my-topic topic, starts consuming from the earliest offset, and sets the print.key and key.separator properties.



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4