What is the recommended way to obtain a list of all partitions that a ConcurrentMessageListenerContainer is currently handling

I am looking for the best/recommended way to obtain a list of partitions that a ConcurrentMessageListenerContainer is using while reading from a topic. Currently I am doing this manually, by having an implementation of ConsumerAwareRebalanceListener that is tracking assignments/revocations but I wonder whether there isn't a better/simpler way to achieve this.

The goal is to use this information within the application, so I always need an up-to-date list of partitions. Looking at the API for ConcurrentMessageListenerContainer, I see that it is exposing getAssignedPartitions().

A similar question has been asked here but there is no accepted answer until now.

Upvotes: 0

Views: 924

Answers (2)

Tim Barabanov
Tim Barabanov

Reputation: 41

Looking at the code in KafkaMessageListenerContainer can't see anything that promises that polling (getting assigned partitions) from a thread distinct from the consumer's thread allows to observe consistent state of the assignedPartitions collection.

Please correct me if I'm wrong.

Upvotes: 1

Linh Vu
Linh Vu

Reputation: 990

If your ConcurrentMessageListenerContainer is managed by KafkaListenerEndpointRegistry, you could use KafkaListenerEndpointRegistry to get information about your listener containers through container's id and you could see the ContainerProperties, AssignedPartitions,... of this listener container.

Example of using KafkaListenerEndpointRegistry: https://docs.spring.io/spring-kafka/docs/current/reference/html/#pause-resume

Upvotes: 2

Related Questions