Search code examples
javaspringspring-kafka

Spring KafkaListener with topicPattern, assign all paritions of all topics


I have @KafkaListener using topicPattern with a regex which works just fine (foo.*), but now I want to assign the listener to all partitions of all matching topics.

The https://docs.spring.io/spring-kafka/docs/2.6.1/reference/html/#tip-assign-all-parts doesn't really help me as I don't know the topic names.


Solution

  • You can't manually assign partitions when using patterns; only group management (Kafka does the assignment) is supported for patterns.

    If there is only one instance of your application, Kafka will assign all the partitions for matching topics. If there are multiple instances and you want them all assigned to all partitions, they must have unique group.ids.