Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a way to execute some logic when the HTTP server is started #42366

Closed
mkouba opened this issue Aug 7, 2024 · 2 comments · Fixed by #42409
Closed

Provide a way to execute some logic when the HTTP server is started #42366

mkouba opened this issue Aug 7, 2024 · 2 comments · Fixed by #42409
Labels
area/vertx kind/enhancement New feature or request
Milestone

Comments

@mkouba
Copy link
Contributor

mkouba commented Aug 7, 2024

Description

StartupEvent/@Startup does not help because the CDI event is fired before the HTTP server is started.

The only workaround I can think of is to schedule a task in a StartupEvent/@Startup to execute some logic with a delay, e.g. something like:

class MyBean {

   @Inject
   ScheduledExecutorService executor;

   @Startup
   void init() {
      executor.schedule(new Task(), 500, TimeUnit.MILLISECONDS);
   }
}

and non-blocking variant:

class MyBean {

   @Inject
   Vertx vertx;

   @Startup
   void init() {
      vertx.setTimer(500, new Handler());
   }
}

This is of course not reliable at all because of the hard-coded delay.

Implementation ideas

We could fire a specific CDI event, or introduce a special interface to be implemented by beans (e.g. HttpServerListener) and called when the server is listening. I'm proposing a CDI-specific API because that's what Quarkus users are used to do.

@mkouba mkouba added the kind/enhancement New feature or request label Aug 7, 2024
@geoand
Copy link
Contributor

geoand commented Aug 8, 2024

+1 for this. I'm pretty sure we've heard of similar requests in the past.

The one complication I can think of is that we would need to provide enough context so the users knows whether it's the HTTP or HTTPS server being started

@mkouba
Copy link
Contributor Author

mkouba commented Aug 8, 2024

The one complication I can think of is that we would need to provide enough context so the users knows whether it's the HTTP or HTTPS server being started

Yes, I was thinking of separate events/methods for HTTP and HTTPS...

mkouba added a commit to mkouba/quarkus that referenced this issue Aug 8, 2024
mkouba added a commit to mkouba/quarkus that referenced this issue Aug 9, 2024
@quarkus-bot quarkus-bot bot added this to the 3.14 - main milestone Aug 9, 2024
danielsoro pushed a commit to danielsoro/quarkus that referenced this issue Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/vertx kind/enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants