spring-cloud / spring-cloud/spring-cloud-stream

Failed to locate function. Returning null. Since only functional binding is now allowed in 4.3.0 cannot consume any messages

Open
#3,163 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
1.1k
Forks
646
Avg merge
2d 3h
Merged PRs (30d)
8

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the MyApplication entry point, the chatRequestListener Consumer bean, and the spring.cloud.function.definition and stream.bindings configuration shown in the report. Reproduce the startup logs with Spring Boot 3.5.5, Spring Cloud 2025.0.0, and spring-cloud-stream 4.3.0, then trace why the named function is not resolved. Done means the Kafka consumer is linked to chatRequestListener and receives messages without the lookup error.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, kafka, spring, spring-boot
Domain
backend, distributed-systems, stream-processing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.