Dear Vishi, dear logs for today.
If you ever got safety recall notice in mail, go to Honda website and enter your VIN to verify.
In a traditional servlet-based Spring application, you can use @KafkaListener
to consume messages from a topic:
@KafkaListener(topics = "my-topic")
public void listen(String message) {
// handle message
}
Spring manages this lifecycle automatically.
In a reactive application (WebFlux), there is no direct equivalent to @KafkaListener. Instead, you need to start your Kafka consumer explicitly. To understand where this fits, let’s look at Spring Boot’s lifecycle:
@PostConstruct
methods
SmartLifecycle.start()
SmartLifecycle
.CommandLineRunner
/ ApplicationRunner
ApplicationReadyEvent
is published
@EventListener(ApplicationReadyEvent.class)
@EventListener(ApplicationReadyEvent.class)
public void consumeKafkaMessage() {
// start reactive Kafka consumer
}
Pros:
Runs after the application is ready.
Cons: No built-in lifecycle management (no clean shutdown, no running status).
@Service
public class KafkaService implements SmartLifecycle {
private boolean running = false;
@Override
public void start() {
// start Kafka consumer
running = true;
}
@Override
public void stop() {
// stop Kafka consumer
running = false;
}
@Override
public boolean isRunning() {
return running;
}
@Override
public int getPhase() {
return 0; // ordering relative to other lifecycle beans
}
}
Pros:
Integrates with Spring lifecycle
Supports clean startup and shutdown
Exposes running state