-
Notifications
You must be signed in to change notification settings - Fork 631
Description
The consumer function cannot be found while binding, but it seems the function is recognized properly.
The spring-cloud-stream version I am using is 4.3.0 and is coming from spring-cloud version 2025.0.0, and spring-boot 3.5.5. Therefore consuming messages (using kafka) is not possible.
Describe the issue
I am trying to listen for a simple kafka topic using functional binding, because there is no other option anyway, so Im stuck with it. The problem is that my Consumer is not being recognized with logs containing:
Failed to locate function 'chatRequestListener' for function definition 'chatRequestListener'. Returning null
When I add more functions, the logs seem to actually mentioned they are found:
Multiple functional beans were found [chatRequestListener, chatRequestListenerTest], thus can't determine default function definition. Please use 'spring.cloud.function.definition' property to explicitly define it.
When I add spring.cloud.function.definition property, I am back to
Failed to locate function 'chatRequestListener' for function definition 'chatRequestListener'. Returning null
To Reproduce
My code is the simplest:
spring:
cloud:
stream:
bindings:
chatRequestListener-in-0:
binder: kafka
destination: chatrequesttopic
content-type: application/json
@SpringBootApplication
public class MyApplication {
private static final Logger logger = LoggerFactory.getLogger(MyApplication.class);
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
@Bean("chatRequestListener")
public static Consumer<Message<ChatMessageDTO>> chatRequestListener(@Autowired MessagingService messagingService){
logger.info("CREATED FUNCTION");
return new ChatMessageListener(messagingService);
}
}
I get the error
Failed to locate function 'chatRequestListener' for function definition 'chatRequestListener'. Returning null
Changed to
@Bean("chatRequestListener")
public static Consumer<Message<ChatMessageDTO>> chatRequestListener(@Autowired WebexApiMessagingService messagingService){
logger.info("CREATED FUNCTION");
return new ChatMessageListener(messagingService);
}
@Bean
public Consumer<Message<ChatMessageDTO>> chatRequestListenerTest(@Autowired WebexApiMessagingService messagingService){
return message -> logger.info("MESSAGE RECEIVED");
}
It seems the functions are actually found:
Multiple functional beans were found [chatRequestListener, chatRequestListenerTest], thus can't determine default function definition. Please use 'spring.cloud.function.definition' property to explicitly define it.
I define the property:
spring:
data:
mongodb:
database: webexservice
cloud:
function:
definition: chatRequestListener
stream:
bindings:
chatRequestListener-in-0:
binder: kafka
destination: chatrequesttopic
content-type: application/json
And now I am back to
Failed to locate function 'chatRequestListener' for function definition 'chatRequestListener'. Returning null
I would expect my consumers would actually be linked, and called on message (at least sending via streamBridge seems to work).
NOTE: I tested with and without static as this might influence bean init order, also the explicity Bean name was done "just to be sure". Also the "CREATED FUNCTION" log item was always before the log items that say there are multiple functions or the "failed to locate function"
The spring boot version: 3.5.5
Spring cloud version: 2025.0.0
Ended up with spring-cloud-stream 4.3.0 in the maven dependency tree