I tried to create a Quarkus App with bare Vertx. However, I can't curl multiple times. Only the first curl give me the correct response.
I tried to use Vertx without Quarkus (main method). Then everything works fine. Each curl gives the correct response. So I think I initialize Vertx wrong when I use Quarkus.
Code: Verticle Deployer
package Super.Company.App;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;
import javax.enterprise.inject.Instance;
import javax.inject.Inject;
import io.quarkus.runtime.StartupEvent;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Verticle;
import io.vertx.core.Vertx;
@ApplicationScoped
public class App {
@Inject
Vertx vertx;
public void init(@Observes StartupEvent e, Vertx vertx, Instance<AbstractVerticle> verticles) {
for (AbstractVerticle verticle : verticles) {
vertx.deployVerticle(verticle);
}
}
public static void main(String[] args) {
Vertx vertx = Vertx.vertx();
Verticle myVerticle = new MyVerticle();
vertx.deployVerticle(myVerticle);
}
}
Code: Verticle
package Super.Company.App;
import javax.enterprise.context.ApplicationScoped;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.http.HttpServer;
import io.vertx.core.http.HttpServerResponse;
import io.vertx.ext.web.Router;
@ApplicationScoped
public class MyVerticle extends AbstractVerticle {
@Override
public void start() {
HttpServer server = vertx.createHttpServer();
Router router = Router.router(vertx);
router.route().handler(routingContext -> {
// This handler will be called for every request
HttpServerResponse response = routingContext.response();
response.putHeader("content-type", "text/plain");
// Write to the response and end it
response.end("Hello World from Vert.x-Web!");
});
server.requestHandler(router).listen(8080);
}
}
edit: I have spammed the curl command and occasionally I got the correct response. Every 16th curl command responds correctly.
update: Besides the curl spamming, I made some tests. I used hey, Postman, Google Chrome and Safari.
hey: 5% - 15% were a 200 and the rest were a 404.
Postman: I received only 404. But after restarting the server, it responds only 200.
Browsers: Only one tab can connect to the server. I can refresh this tap multiple times and the server sends a 200 each time. I have to restart the server to connect with other tabs. However, if I refresh the other tabs they get a 404.