Update message-listener-container.adoc (#3504)

* Fix typo in `message-listener-container.adoc`

* Replace deprecated `PartitionAssignor` with `ConsumerPartitionAssignor` in `message-listener-container.adoc`
This commit is contained in:
Hao
2024-09-21 00:49:58 +08:00
committed by GitHub
parent 10ea5bfc51
commit ccd7215e67

View File

@@ -139,10 +139,10 @@ For the first constructor, Kafka distributes the partitions across the consumers
====
When listening to multiple topics, the default partition distribution may not be what you expect.
For example, if you have three topics with five partitions each and you want to use `concurrency=15`, you see only five active consumers, each assigned one partition from each topic, with the other 10 consumers being idle.
This is because the default Kafka `PartitionAssignor` is the `RangeAssignor` (see its Javadoc).
This is because the default Kafka `ConsumerPartitionAssignor` is the `RangeAssignor` (see its Javadoc).
For this scenario, you may want to consider using the `RoundRobinAssignor` instead, which distributes the partitions across all of the consumers.
Then, each consumer is assigned one topic or partition.
To change the `PartitionAssignor`, you can set the `partition.assignment.strategy` consumer property (`ConsumerConfigs.PARTITION_ASSIGNMENT_STRATEGY_CONFIG`) in the properties provided to the `DefaultKafkaConsumerFactory`.
To change the `ConsumerPartitionAssignor`, you can set the `partition.assignment.strategy` consumer property (`ConsumerConfig.PARTITION_ASSIGNMENT_STRATEGY_CONFIG`) in the properties provided to the `DefaultKafkaConsumerFactory`.
When using Spring Boot, you can assign set the strategy as follows: