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.
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";
};
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.