Issue
We are using the ConcurrentMessageListenerContainer
to create our Kafka href="https://kafka.apache.org/20/javadoc/org/apache/kafka/clients/consumer/Consumer.html" rel="nofollow noreferrer">Consumer
s.
With the ConcurrentMessageListenerContainer#concurrency
property it is possible to create multiple consumers.
Is it possible in a Spring Boot application to inject all Consumer
s created by the ConcurrentMessageListenerContainer
? Or is it possible to obtain them somehow after an ApplicationEvent
?
Solution
Why do you need access to the underlying Consumer
objects? They are managed by the container.
The consumer is available as a parameter in the message listener and is included in published events, but using the Consumer
API directly is not recommended because such usage might conflict with the container's expectations.
It's ok to use passive APIs, such as getting the end offsets of subscribed topics.
Answered By - Gary Russell
Answer Checked By - David Marino (JavaFixing Volunteer)