Start Reactive Receiver after Spring Boot main method or after some event

58 Views Asked by At

I am using Reactor Kafka, but cannot solve the following problem. Is it possible to configure Receiver to start after the application is fully launched, rather than at the moment with the application? Or, for example, that the Receiver is launched after some event? I couldn't find information about it in the documentation :-(

1

There are 1 best solutions below

0
Artem Bilan On

I wonder how do you launch that receiver at the moment. To be precise there is nothing in Spring Boot which would start consuming from that Kafka receiver automatically. You have to subscribe() into the result Flux somehow in your code. And that is exactly what you can control in your code. For example, you can catch an ApplicationReadyEvent or have an ApplicationRunner bean. And call some your service which is going to subscribe() to the Flux from receiver.

Even Spring for Apache Kafka with its @KafkaListener starts consuming only if the application is fully ready. But Reactor Kafka has nothing to do with Spring. You probably just subscribe() at some wrong spot.