diff --git a/inventory-vertx/pom.xml b/inventory-vertx/pom.xml index 230944e..899b6bc 100644 --- a/inventory-vertx/pom.xml +++ b/inventory-vertx/pom.xml @@ -144,7 +144,7 @@ true - -Djava.net.preferIPv4Stack=true + -Djava.net.preferIPv4Stack=true -Dhttp.port=9001 diff --git a/solutions/gateway-vertx/GatewayVerticle.java b/solutions/gateway-vertx/GatewayVerticle.java index 0195067..78c052b 100644 --- a/solutions/gateway-vertx/GatewayVerticle.java +++ b/solutions/gateway-vertx/GatewayVerticle.java @@ -67,8 +67,8 @@ private void products(RoutingContext rc) { // Retrieve catalog catalog .get("/api/catalog") - .as(BodyCodec.jsonArray()) .expect(ResponsePredicate.SC_OK) + .as(BodyCodec.jsonArray()) .rxSend() .map(resp -> { // Map the response to a list of JSON object @@ -79,11 +79,11 @@ private void products(RoutingContext rc) { return listOfProducts; }) .flatMap(products -> { - // For each item from the catalog, invoke the inventory service - // and create a JsonArray containing all the results - return Observable.fromIterable(products) - .flatMapSingle(this::getAvailabilityFromInventory) - .collect(JsonArray::new, JsonArray::add); + // For each item from the catalog, invoke the inventory service + // and create a JsonArray containing all the results + return Observable.fromIterable(products) + .flatMapSingle(this::getAvailabilityFromInventory) + .collect(JsonArray::new, JsonArray::add); } ) .subscribe( @@ -96,19 +96,16 @@ private Single getAvailabilityFromInventory(JsonObject product) { // Retrieve the inventory for a given product return inventory .get("/api/inventory/" + product.getString("itemId")) + .expect(ResponsePredicate.SC_OK) .as(BodyCodec.jsonObject()) .rxSend() - .map(resp -> { - JsonObject json = product.copy(); - if (resp.statusCode() != 200) { - LOG.warn("Inventory error for {}: status code {}", - product.getString("itemId"), resp.statusCode()); - } else { - json.put("availability", - new JsonObject() - .put("quantity", resp.body().getInteger("quantity"))); - } - return json; + .map(resp -> product.copy() + .put("availability", + new JsonObject() + .put("quantity", resp.body().getInteger("quantity")))) + .onErrorReturn(err -> { + LOG.warn("Inventory error for {}: status code {}", product.getString("itemId"), err); + return product.copy(); }); } -} \ No newline at end of file +} diff --git a/solutions/inventory-vertx/madou.txt b/solutions/inventory-vertx/madou.txt deleted file mode 100644 index be4318c..0000000 --- a/solutions/inventory-vertx/madou.txt +++ /dev/null @@ -1,8 +0,0 @@ -# Changes from Thorntail: - -- config map file is named "app-config.yml" -- port is 8080 by default and can be overriden with http.port env - -CLI for config: -- oc create configmap inventory --from-file=./app-config.yml -- oc set volume dc/inventory --add --configmap-name=inventory --mount-path=/deployments/config