Skip to content

Commit

Permalink
allow setting cart endpoint in gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
siamaksade committed Oct 10, 2017
1 parent a1749b2 commit 1123ebc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,21 @@ public void start() {
.setDefaultPort(Integer.getInteger("inventory.api.port", 9001))));

// Cart lookup
Single<WebClient> cartDiscoveryRequest = HttpEndpoint.rxGetWebClient(discovery,
rec -> rec.getName().equals("cart"))
.onErrorReturn(t -> WebClient.create(vertx, new WebClientOptions()
.setDefaultHost(System.getProperty("cart.api.host", "localhost"))
.setDefaultPort(Integer.getInteger("cart.api.port", 9002))));
Single<WebClient> cartDiscoveryRequest;
String cartEndpoint = System.getenv("CART_ENDPOINT_HOST");

if (cartEndpoint != null) {
cartDiscoveryRequest = Single.just(WebClient.create(vertx,
new WebClientOptions()
.setDefaultHost(cartEndpoint)
.setDefaultPort(80)));
} else {
cartDiscoveryRequest = HttpEndpoint.rxGetWebClient(discovery,
rec -> rec.getName().equals("cart"))
.onErrorReturn(t -> WebClient.create(vertx, new WebClientOptions()
.setDefaultHost(System.getProperty("cart.api.host", "localhost"))
.setDefaultPort(Integer.getInteger("cart.api.port", 9002))));
}

// Zip all 3 requests
Single.zip(catalogDiscoveryRequest, inventoryDiscoveryRequest, cartDiscoveryRequest, (c, i, ct) -> {
Expand Down
19 changes: 5 additions & 14 deletions openshift/coolstore-deployment-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ objects:
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: COOLSTORE_GW_ENDPOINT
value: http://gw-${HOSTNAME_SUFFIX}
- name: COOLSTORE_GW_SERVICE
value: gw
- name: HOSTNAME_HTTP
value: web-ui:8080
image: web-ui
Expand Down Expand Up @@ -122,7 +122,6 @@ objects:
application: coolstore
component: web-ui
spec:
host: web-ui-${HOSTNAME_SUFFIX}
to:
kind: Service
name: web-ui
Expand Down Expand Up @@ -157,10 +156,6 @@ objects:
fieldPath: metadata.namespace
- name: CART_ENDPOINT
value: cart-${HOSTNAME_SUFFIX}
- name: INVENTORY_ENDPOINT
value: inventory-${HOSTNAME_SUFFIX}
- name: CATALOG_ENDPOINT
value: catalog-${HOSTNAME_SUFFIX}
image: library/coolstore-gw:${APP_VERSION}
livenessProbe:
httpGet:
Expand Down Expand Up @@ -202,7 +197,7 @@ objects:
application: coolstore
component: coolstore-gw
hystrix.enabled: "true"
name: coolstore-gw
name: gw
spec:
ports:
- port: 8080
Expand All @@ -213,15 +208,14 @@ objects:
- apiVersion: v1
kind: Route
metadata:
name: coolstore-gw
name: gw
labels:
application: coolstore
component: coolstore-gw
spec:
host: gw-${HOSTNAME_SUFFIX}
to:
kind: Service
name: coolstore-gw
name: gw
# Catalog Service
- apiVersion: v1
kind: DeploymentConfig
Expand Down Expand Up @@ -337,7 +331,6 @@ objects:
component: catalog
name: catalog
spec:
host: catalog-${HOSTNAME_SUFFIX}
to:
kind: Service
name: catalog
Expand Down Expand Up @@ -576,7 +569,6 @@ objects:
component: cart
name: cart
spec:
host: cart-${HOSTNAME_SUFFIX}
to:
kind: Service
name: cart
Expand Down Expand Up @@ -716,7 +708,6 @@ objects:
component: inventory
name: inventory
spec:
host: inventory-${HOSTNAME_SUFFIX}
to:
kind: Service
name: inventory
Expand Down

0 comments on commit 1123ebc

Please sign in to comment.