After the Update to 4.0.4 we have the bug that sometimes a function can't be found and therefore also our KStream is not working.
After a long investigation I found the problem in the KafkaStreamsFunctionBeanPostProcessor in the method extractResolvableTypes.
In this method the bean will be loaded by the function name and with the bean the runtime tries to find the method reference of this function.
Unfortunately the static method KafkaStreamsBinderUtils.findMethodWithName will be used to find this method, which just check the method name, but not the incoming parameter or the return type:
https://github.com/spring-cloud/spring-cloud-stream/blame/4c876b1a7f8222112b253e6f9f51a626201202bc/binders/kafka-binder/spring-cloud-stream-binder-kafka-streams/src/main/java/org/springframework/cloud/stream/binder/kafka/streams/function/KafkaStreamsFunctionBeanPostProcessor.java#L181
That means when you have multiple methods in your class with the same name (e.g. a method with KStream and a method with String as return), you can got the wrong method back, because it's just a check on method name and the check if the return type is correct will fail:
https://github.com/spring-cloud/spring-cloud-stream/blame/4c876b1a7f8222112b253e6f9f51a626201202bc/binders/kafka-binder/spring-cloud-stream-binder-kafka-streams/src/main/java/org/springframework/cloud/stream/binder/kafka/streams/function/KafkaStreamsFunctionBeanPostProcessor.java#L196
A workaround is simple, don't use method names twice but this can't be the general solution.
In my opinion the stream in the method KafkaStreamsBinderUtils.findMethodWithName should extends by filtering the return type of the method. So that only methods with KStream, KTable or GlobalKTable will be returned.
After the Update to 4.0.4 we have the bug that sometimes a function can't be found and therefore also our KStream is not working.
After a long investigation I found the problem in the KafkaStreamsFunctionBeanPostProcessor in the method extractResolvableTypes.
In this method the bean will be loaded by the function name and with the bean the runtime tries to find the method reference of this function.
Unfortunately the static method KafkaStreamsBinderUtils.findMethodWithName will be used to find this method, which just check the method name, but not the incoming parameter or the return type:
https://github.com/spring-cloud/spring-cloud-stream/blame/4c876b1a7f8222112b253e6f9f51a626201202bc/binders/kafka-binder/spring-cloud-stream-binder-kafka-streams/src/main/java/org/springframework/cloud/stream/binder/kafka/streams/function/KafkaStreamsFunctionBeanPostProcessor.java#L181
That means when you have multiple methods in your class with the same name (e.g. a method with KStream and a method with String as return), you can got the wrong method back, because it's just a check on method name and the check if the return type is correct will fail:
https://github.com/spring-cloud/spring-cloud-stream/blame/4c876b1a7f8222112b253e6f9f51a626201202bc/binders/kafka-binder/spring-cloud-stream-binder-kafka-streams/src/main/java/org/springframework/cloud/stream/binder/kafka/streams/function/KafkaStreamsFunctionBeanPostProcessor.java#L196
A workaround is simple, don't use method names twice but this can't be the general solution.
In my opinion the stream in the method KafkaStreamsBinderUtils.findMethodWithName should extends by filtering the return type of the method. So that only methods with KStream, KTable or GlobalKTable will be returned.