simonC
simonC

Reputation: 4337

How to execute some code on Quarkus AFTER the application has completely started?

I am aware os the @Startup annotation or the startup observer but I how can I run something after all beans are created and the application is fully run?

Upvotes: 0

Views: 486

Answers (1)

simonC
simonC

Reputation: 4337

Until there is a built in feature I went with a custom solution like this:

A custom @QuarkusMain where in the run method whch is executed after app is started I send and event and where you want to listen to this event you can apply some custom logic.

@QuarkusMain
public class Main {
    public static void main(String... args) {
        Quarkus.run(Websocket.class, args);
    }

    public static class Websocket implements QuarkusApplication {
        @Inject
        EventBus bus;

        @Override
        public int run(String... args) {
            LOG.info("Application started");
            bus.send("after-start-init-event", "init");
            Quarkus.waitForExit();
            return 0;
        }
    }
}

Upvotes: 0

Related Questions