Skip to content

Commit cc0bdef

Browse files
garyrussellartembilan
authored andcommitted
GH-1808: Fix Container Properties Crosstalk
Resolves #1808 Each container got a reference to the same `Properties` object in `kafkaConsumerProperties`, unless it was created via a `@KafkaListener` with property overrides. Do not copy the property from the factory's properties. **Cherry-pick to all supported branches**
1 parent 3918d9e commit cc0bdef

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

spring-kafka/src/main/java/org/springframework/kafka/config/AbstractKafkaListenerContainerFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ private void configureEndpoint(AbstractKafkaListenerEndpoint<K, V> aklEndpoint)
389389
protected void initializeContainer(C instance, KafkaListenerEndpoint endpoint) {
390390
ContainerProperties properties = instance.getContainerProperties();
391391
BeanUtils.copyProperties(this.containerProperties, properties, "topics", "topicPartitions", "topicPattern",
392-
"messageListener", "ackCount", "ackTime", "subBatchPerPartition");
392+
"messageListener", "ackCount", "ackTime", "subBatchPerPartition", "kafkaConsumerProperties");
393393
JavaUtils.INSTANCE
394394
.acceptIfNotNull(this.afterRollbackProcessor, instance::setAfterRollbackProcessor)
395395
.acceptIfCondition(this.containerProperties.getAckCount() > 0, this.containerProperties.getAckCount(),

spring-kafka/src/test/java/org/springframework/kafka/annotation/ContainerFactoryTests.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ public void testConfigContainer() {
5454
assertThat(container.getContainerProperties().getAckCount()).isEqualTo(123);
5555
assertThat(KafkaTestUtils.getPropertyValue(container, "concurrency", Integer.class)).isEqualTo(22);
5656
assertThat(customized).isTrue();
57+
ConcurrentMessageListenerContainer<String, String> container2 = factory.createContainer("foo");
58+
assertThat(container.getContainerProperties().getKafkaConsumerProperties())
59+
.isNotSameAs(container2.getContainerProperties().getKafkaConsumerProperties());
5760
}
5861

5962
}

0 commit comments

Comments
 (0)