souvikc
souvikc

Reputation: 1031

Kafka multiple consumer from different partitions

I have 4 partitions and 4 consumers(A,B,C,D for example). How to configure which consumer will read from which partition using consumer groups. I am using Kafka with Spring boot.

Upvotes: 1

Views: 1111

Answers (1)

Gary Russell
Gary Russell

Reputation: 174484

By default, kafka will automatically assign the partitions; if you have 4 consumers in the same group, they will eventually get one partition each. There are properties to configure kafka so it won't immediately do the allocation while you bring up your consumers.

You can also assign the partitions yourself.

Using

public ContainerProperties(TopicPartitionInitialOffset... topicPartitions)

if you are building the container yourself, or

@KafkaListener(id = "baz", topicPartitions = @TopicPartition(topic = "${topic}",
            partitions = "${partition}"))

if you are using @KafkaListener.

Upvotes: 1

Related Questions