JPS
JPS

Reputation: 426

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.

Upvotes: 0

Views: 1032

Answers (3)

Laurent Perez
Laurent Perez

Reputation: 658

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.

Upvotes: 0

JPS
JPS

Reputation: 426

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.

Upvotes: 0

Panu Haaramo
Panu Haaramo

Reputation: 2932

Use @PostConstruct method in your REST resource bean.

Upvotes: 0

Related Questions