Skip to content

Commit 6484a2f

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 dc881d9 commit 6484a2f

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
@@ -401,7 +401,7 @@ private void configureEndpoint(AbstractKafkaListenerEndpoint<K, V> aklEndpoint)
401401
protected void initializeContainer(C instance, KafkaListenerEndpoint endpoint) {
402402
ContainerProperties properties = instance.getContainerProperties();
403403
BeanUtils.copyProperties(this.containerProperties, properties, "topics", "topicPartitions", "topicPattern",
404-
"messageListener", "ackCount", "ackTime", "subBatchPerPartition");
404+
"messageListener", "ackCount", "ackTime", "subBatchPerPartition", "kafkaConsumerProperties");
405405
JavaUtils.INSTANCE
406406
.acceptIfNotNull(this.afterRollbackProcessor, instance::setAfterRollbackProcessor)
407407
.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
@@ -59,6 +59,9 @@ void testConfigContainer() {
5959
assertThat(container.getContainerProperties().getAckCount()).isEqualTo(123);
6060
assertThat(KafkaTestUtils.getPropertyValue(container, "concurrency", Integer.class)).isEqualTo(22);
6161
assertThat(customized).isTrue();
62+
ConcurrentMessageListenerContainer<String, String> container2 = factory.createContainer("foo");
63+
assertThat(container.getContainerProperties().getKafkaConsumerProperties())
64+
.isNotSameAs(container2.getContainerProperties().getKafkaConsumerProperties());
6265
}
6366

6467
@SuppressWarnings("unchecked")

0 commit comments

Comments
 (0)