quarkus
quarkus copied to clipboard
Add Lifecycle onReady event
Description Following logic on lifecycle documentation we can see that we have can register for startup and shuttdown events. It could be useful to have an event when the app is ready.
/cc @mkouba
We would need to define what "ready" means?
You are right. Like for Angular. We should define life cycle. We could imagine:
- when All Applications coped Beans are Instantiated
- when application can receive traffic
I am thinking about other ideas 🤔
- all
@Startupbeans are done?
when All Applications coped Beans are Instantiated
@speedfl This is not valid in the context of CDI because @ApplicationScoped beans are instantiated lazily...
when application can receive traffic
That's a good point. However, it might make more sense to create a specific event for this, e.g. HttpServerStarted. @stuartwdouglas @gsmet WDYT? In theory, we could fire this event after this line, or?
all @Startup beans are done?
Well, and then we could introduce a new event that will be fired after all observers of this event are notified, etc. ;-).
In fact, you can specify a priority for your observer or a @Startup bean. Observers with smaller priority are called first. But the truth is that you can only be sure that your observer is notified before the ones with the default priority, which is 2500.
@mkouba any update on this, I think having an event when it's ready to receive request (health check ready when implemented)
@mkouba any update on this, I think having an event when it's ready to receive request (health check ready when implemented)
That might be an interesting addition to the SR Health extension. WDYT @xstefank
Sure, on top of my head, this should be doable. I'll look.
Hello,
As I understand it, the events implemented in the PR above are not raised immediately after the application becomes ready. Currently, the events are only triggered when the Health Status changes after startup.
Here is my observer implementation:
package ru.saleinc.standalone;
import io.quarkus.runtime.StartupEvent;
import io.smallrye.health.api.event.HealthStatusChangeEvent;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.event.Observes;
import jakarta.enterprise.inject.Default;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.microprofile.health.Liveness;
import org.eclipse.microprofile.health.Readiness;
@ApplicationScoped
@Slf4j
public class StartupAction {
void onStart(@Observes StartupEvent event) {
System.out.println("ON_START_EVENT_CAPTURED");
}
public void observeHealthChange(@Observes @Default HealthStatusChangeEvent event) {
System.out.println("DEFAULT_EVENT_CAPTURED");
}
public void observeLiveness(@Observes @Liveness HealthStatusChangeEvent event) {
System.out.println("LIVENESS_EVENT_CAPTURED");
}
public void observeReadiness(@Observes @Readiness HealthStatusChangeEvent event) {
System.out.println("READINESS_EVENT_CAPTURED");
}
}
AR: None of the observer methods are called immediately after a successful startup. ER: I would expect to see the following logs right after startup:
ON_START_EVENT_CAPTURED
2025-04-11 15:05:06,960 INFO [io.quarkus] (Quarkus Main Thread) saleinc-standalone 1.0-SNAPSHOT on JVM (powered by Quarkus 3.21.2) started in 2.242s. Listening on: http://localhost:59192
LIVENESS_EVENT_CAPTURED
READINESS_EVENT_CAPTURED
Given that the probes' status transitions occur during startup, it would be reasonable to expect these events to be emitted immediately. At the very least, introducing an explicit onReady event—as previously suggested would also address this issue. IMHO, an onReady event is the best solution.
So there is still no event that fires right after the application becomes fully ready.