I am trying to perform a http call using Java vertx. Below is my sample code which I am using to perform a http post call. After executing this code, I can receive the response but log messages which is written inside onsuccess or onFailure(when failure occur) or onComplete methods are not printing. Kindly help me to rectify the issue here.
WebClient httpClient; VertxOptions vertxOption = new VertxOptions() .setBlockedThreadCheckInterval(config.getBlockedThreadCheckInterval()) .setBlockedThreadCheckIntervalUnit(TimeUnit.SECONDS) .setMaxEventLoopExecuteTime(config.getMaxEventLoopExecutionTime()) .setMaxEventLoopExecuteTimeUnit(TimeUnit.SECONDS) .setWarningExceptionTime(config.getWarningExecutionTime()) .setWarningExceptionTimeUnit(TimeUnit.SECONDS) .setMaxWorkerExecuteTime(config.getMaxWorkerExecutionTime()) .setMaxWorkerExecuteTimeUnit(TimeUnit.SECONDS); //.setWorkerPoolSize(config.getPoolSize());
WebClientOptions options = new WebClientOptions(); options .setName(config.getVertxName()) .setConnectTimeout(config.getHttpConnectionTimeout() * 1000) .setTrustAll(config.isHttpTrustAll()) .setKeepAlive(config.isHttpKeepAlive()) .setIdleTimeout(config.getHttpConnectionTimeout()) .setHttp2KeepAliveTimeout(config.getHttpConnectionTimeout()) .setMaxPoolSize(config.getPoolSize()); Vertx vertx = Vertx.vertx(vertxOption) .exceptionHandler(Throwable::printStackTrace); try{ httpClient = WebClient.create(vertx, options); } catch (Exception e) { log.error("Error while starting vertx client {0} ",e.getCause()); } httpClient .postAbs("http://localhost:8080/traveldetails/enquery") .expect(ResponsePredicate.SC_SUCCESS) .as(BodyCodec.pipe(new KryoStreamWriter<>(consumer, latch))) .sendBuffer(buffer) .onSuccess(res->{ future.complete("Future Complete"); log.info("success response...................."); }) .onFailure(frc->{ log.error("failure response"); log.error("Error : {}", frc.getCause()); future.completeExceptionally(new Throwable("Error occur in vertx")); }).onComplete(asyncResult ->{ System.out.println("Status value "+asyncResult.result().statusCode()); if(asyncResult.succeeded()) log.info("On Complete............................ and status code {}", asyncResult.result().statusCode()); else log.error("Failed to get complete the request {} ", asyncResult.result().statusCode()); latch.countDown(); });