Skip to content

Commit 9f828a8

Browse files
garyrussellartembilan
authored andcommitted
1 parent e16ae4f commit 9f828a8

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/reference/asciidoc/kafka.adoc

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,25 @@ public ConcurrentMessageListenerContainer(ConsumerFactory<K, V> consumerFactory,
655655

656656
It also has a property `concurrency`, e.g. `container.setConcurrency(3)` will create 3 `KafkaMessageListenerContainer` s.
657657

658-
For the first constructor, kafka will distribute the partitions across the consumers.
658+
For the first constructor, kafka will distribute the partitions across the consumers using its group management capabilities.
659+
660+
[IMPORTANT]
661+
====
662+
When listening to multiple topics, the default partition distribution may not be what you expect.
663+
For example, if you have 3 topics with 5 partitions each and you want to use `concurrency=15` you will only see 5 active consumers, each assigned one partition from each topic, with the other 10 consumers being idle.
664+
This is because the default Kafka `PartitionAssignor` is the `RangeAssignor` (see its javadocs).
665+
For this scenario, you may want to consider using the `RoundRobinAssignor` instead, which will distribute the partitions across all of the consumers.
666+
Then, each consumer will be assigned one topic/partition.
667+
To change the `PartitionAssignor`, set the `partition.assignment.strategy` consumer property (`ConsumerConfigs.PARTITION_ASSIGNMENT_STRATEGY_CONFIG`) in the properties provided to the `DefaultKafkaConsumerFactory`.
668+
669+
When using Spring Boot:
670+
671+
[source]
672+
----
673+
spring.kafka.consumer.properties.partition.assignment.strategy=org.apache.kafka.clients.consumer.RoundRobinAssignor
674+
----
675+
====
676+
659677
For the second constructor, the `ConcurrentMessageListenerContainer` distributes the `TopicPartition` s across the
660678
delegate `KafkaMessageListenerContainer` s.
661679

0 commit comments

Comments
 (0)