I'm trying to get the port Quarkus is listening for HTTP connections on at startup (so that I can send a message to Consul to register the service).
The quarkus.http.port property is set to 0 so that a random port is selected at startup. I'm send the message to Consul in an @Observes StartupEvent method, but the quarkus.http.port property is null at this point. If I add a timer and schedule a function to run after 10 seconds, the quarkus.http.port property does contain the port.
It seems that my onStartup function is ran before Quarkus has actually opened the HTTP port. Is there anyway that I can schedule onStartup to execute after the port has been opened?
@ApplicationScoped
public class TestClass
{
public void onStartup(@Observes StartupEvent event)
{
String port = System.getProperty("quarkus.http.port");
// port is null here
Log.infof("Port: %s", port);
new Timer().schedule(new TimerTask()
{
@Override
public void run()
{
String port = System.getProperty("quarkus.http.port");
// port contains a string like "41069"
Log.infof("Port: %d", port);
}
}, 7000L);
}
}