'How to run code in quarkus once all rest services are deployt (reachable)?
I am writing a quarkus that makes itself known to other servers. Those other servers then want to use my resources.
This fails, because I inform them about the quarkus startup before my own services are actually available.
I currently use
void onStart(@Observes StartupEvent ev) { ... }
to run code at startup.
But this triggers before of my rest services are available.
How can I execute Code in quarkus after everything in this quarkus instance is "ready" to be used?
I am looking basically for a: "EveryThingIsReadyEvent" I can observe.
Solution 1:[1]
Use @PostConstruct method in your REST resource bean.
Solution 2:[2]
What we do now is we start a thread in the onStartup and there we call the ApplicationLifecycleManager and use the "waitForApplicationStart()" Method.
At that point everything that runs after is started.
Solution 3:[3]
This may be about readiness and not necessarily post construction.
To make yourself known to be ready, you could probably implement your own https://quarkus.io/guides/smallrye-health readiness endpoints and let other servers callback your /q/health enpoint
Once all of your enpoints are truly ready as in "UP" string exists and http status code 200 exists, then your app is truly ready.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Panu Haaramo |
| Solution 2 | JPS |
| Solution 3 | Laurent Perez |
