1

In Spring Cloud Stream, I used the functional model and created a Supplier to generateEvents. As per the documentation, I expect that this supplier will get invoked on a scheduled basis, but that's not happening. It gets invoked once upon bean creation, and never again. I'd appreciate any help in figuring out why.

EventSource.java (Supplier):

@Component
@Slf4j
public class EventSource {

    @Bean
    public Supplier<String> generateEvents() {
        log.debug("creating an event to publish to Kafka");
        return () -> "Hi I'm an event";
    }

}

application.yml:

spring:
  cloud:
    function:
      definition: generateEvents
    stream:
      bindings:
        generateEvents-out-0:
          destination: eventsTopic

I know I'm connecting to Kafka, because the topic eventsTopic gets created upon startup. The Cloud Stream app stays up, but doesn't do anything.

jned
  • 11
  • 3
  • I just tested it and all works as expected. There are also many tests to validate. Perhaps you can post a small project that reproduces the issue somewhere in GithUb where we can tale a look? – Oleg Zhurakousky Jun 02 '21 at 16:11
  • The `debug` log in the bean definition will only be called once; you need to move it inside the lambda if you want to log on every event. – Gary Russell Jun 02 '21 at 16:36
  • Did you find a solution to this? I have a similar issue where the Supplier does not seem to be called! – Orwa kassab Mar 28 '23 at 09:50

1 Answers1

0

You can follow this code and I hope you solve the problem:

@Configuration
@Slf4j
public class EventSource {

    @Bean
    public Supplier<String> generateEvents() {
        return () -> {
            log.debug("creating an event to publish to Kafka");
            return "Hi I'm an event";
        };
    }
}
Minh Trần
  • 27
  • 1
  • 5