Skip to content

Commit

Permalink
Merge pull request #6 from vietj/ocp-3.11
Browse files Browse the repository at this point in the history
Updated for inventory-vertx
  • Loading branch information
mcouliba authored May 2, 2019
2 parents 5dacd2d + 9679100 commit c21c917
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 27 deletions.
2 changes: 1 addition & 1 deletion inventory-vertx/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
</executions>
<configuration>
<redeploy>true</redeploy>
<jvmArgs>-Djava.net.preferIPv4Stack=true</jvmArgs>
<jvmArgs>-Djava.net.preferIPv4Stack=true -Dhttp.port=9001</jvmArgs>
</configuration>
</plugin>
<plugin>
Expand Down
33 changes: 15 additions & 18 deletions solutions/gateway-vertx/GatewayVerticle.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -96,19 +96,16 @@ private Single<JsonObject> 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();
});
}
}
}
8 changes: 0 additions & 8 deletions solutions/inventory-vertx/madou.txt

This file was deleted.

0 comments on commit c21c917

Please sign in to comment.