spring-cloud / spring-cloud-stream-binder-kafka

Spring Cloud Stream binders for Apache Kafka and Kafka Streams
Apache License 2.0
331 stars 301 forks source link

streamConfigGlobalProperties overriden for subsequent functions #1149

Closed yanayita closed 3 years ago

yanayita commented 3 years ago

Given an application with multiple functions using Kafka Streams Binder:

spring.cloud.stream.function.definition=function1,function2,function3

spring.cloud.stream.bindings.function1-in-0.destination=topic1-in
spring.cloud.stream.bindings.function1-out-0.destination=topic1-out

spring.cloud.stream.bindings.function2-in-0.destination=topic2-in
spring.cloud.stream.bindings.function2-out-0.destination=topic2-out
spring.cloud.stream.kafka.streams.bindings.function2-in-0.consumer.configuration.spring.json.value.type.method=com.test.MyClass.determineType

spring.cloud.stream.bindings.function3-in-0.destination=topic3-in
spring.cloud.stream.bindings.function3-out-0.destination=topic3-out

I would expect that that the specific configuration added for the consumer in the function2 binding, would apply only to that binding.

However, in reality the observed behaviour while debugging is that the functions are initialised alphabetically and when the following line is executed during function2 initialisation:

https://github.com/spring-cloud/spring-cloud-stream-binder-kafka/blob/a8c948a6b25699abfdededc42cf371970bdf04e4/spring-cloud-stream-binder-kafka-streams/src/main/java/org/springframework/cloud/stream/binder/kafka/streams/AbstractKafkaStreamsBinderProcessor.java#L274

The streamConfigGlobalProperties bean is updated with the additional configuration specific to function2; so when function3 is initialised the extra configuration from function2 is carried over.

Version of the framework Spring Boot 2.5.1 Spring Cloud 2020.0.3

sobychacko commented 3 years ago

@yanayita Thanks for this report. This problem is now addressed. Changes are in main upstream and backported to 3.1.x.

eduard-dominguez-se commented 3 years ago

Excellent. Thanks @sobychacko !