Code Bug Fix: Response not submitted when rxEnd is used in HTTP server

Original Source Link

I have a two verticle server written in vert.x + reactive extensions. HTTP server verticle uses event bus to send requests to the DB verticle. After receiving the response from the DB verticle (through event bus) I send the response to the http client using rxEnd. However clients does not seem to receive this response and times out eventually. If I were to use end() instead, things work fine. I use postman to test this REST API. Please see below for the code which forward results from the DB verticle to client.

routerFactory.addHandlerByOperationId("createChargePoints", routingContext -> {
            RequestParameters params = routingContext.get("parsedParameters");

            RequestParameter body = params.body();
            JsonObject jsonBody = body.getJsonObject();

            vertx.eventBus().rxRequest("dbin", jsonBody)
                    .map(message -> {
                        System.out.println(message.body());
                        return routingContext.response().setStatusCode(200).rxEnd(message.body().toString());
                    })
                    .subscribe(res -> {
                        System.out.println(res);
                    }, res -> {
                        System.out.println(res);
                    });
        });

The rxEnd method is a variant of end that returns a Completable. The former is lazy, the latter is not.

In other words, if you invoke rxEnd you have to subscribe to the Completable otherwise nothing happens.

Looking at the code of your snippet, I don’t believe using rxEnd is necessary. Indeed, it doesn’t seem like you need to know if the request was sent succesfully.

Tagged :

Leave a Reply

Your email address will not be published. Required fields are marked *