-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Affects Version(s): 2.7.0
🎁 Enhancement
When manually creating a listener container via listener container factory org.springframework.kafka.config.AbstractKafkaListenerContainerFactory#createContainer(java.lang.String...)
method the listener container is initialized with properties from the factory.
The org.springframework.kafka.config.AbstractKafkaListenerContainerFactory#initializeContainer
method sets listener container's kafkaConsumerProperties
as a reference to the factory consumerProperties
.
When calling code then changes kafkaConsumerProperties
of the created listener container the changes affect all other listener containers which is the problem.
Because of this it is impossible to create two listener containers with different offset reset policies for example:
ConcurrentMessageListenerContainer<String, String> container1 = listenerContainerFactory.createContainer("topic");
container1.getContainerProperties().setGroupId("group1");
container1.getContainerProperties().getKafkaConsumerProperties().setProperty(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "lateset");
ConcurrentMessageListenerContainer<String, String> container2 = listenerContainerFactory.createContainer("topic");
container2.getContainerProperties().setGroupId("group2");
container2.getContainerProperties().getKafkaConsumerProperties().setProperty(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
Both listeners in the snippet end up with "earliest" offset reset policy.
A way to fix this would be creating a copy of factory consumerProperties
before setting it for the listener container.