Java Magazine, Jan/Feb 2018
ORACLE COM JAVAMAGAZINE JANUARY FEBRUARY 2018 55 reactive programming We can now focus on the implementation of the findBestOffer method It first issues HTTP requests to each service obtaining a list of Single JsonObject responses and then it reduces them to the single best response and eventually ends the HTTP response private final AtomicLong requestIds new AtomicLong private static final JsonObject EMPTY_ RESPONSE new JsonObject put empty true put bid Integer MAX_ VALUE private void findBestOffer HttpServerRequest request String requestId String valueOf requestIds getAndIncrement List Single JsonObject responses targets stream map t webClient get t getInteger port t getString host t getString path putHeader Client Request Id String valueOf requestId as BodyCodec jsonObject rxSend retry 1 timeout 500 TimeUnit MILLISECONDS RxHelper scheduler vertx map HttpResponse body map body logger info received offer requestId body encodePrettily return body onErrorReturnItem EMPTY_ RESPONSE
You must have JavaScript enabled to view digital editions.