Skip to content

Commit 1ae5da4

Browse files
committed
Configuring API gateway
- All test cases runs for the whole system. - test-em-all runs successfully. - More reduction application.yml properties
1 parent 9e25dcf commit 1ae5da4

File tree

13 files changed

+97
-128
lines changed

13 files changed

+97
-128
lines changed

docker-compose-kafka.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ services:
9494
## Start - Store service definition
9595
store:
9696
build: store-services/store-service
97-
ports:
98-
- "8080:8080"
9997
environment:
10098
- SPRING_PROFILES_ACTIVE=docker
10199
- MANAGEMENT_HEALTH_RABBIT_ENABLED=false
@@ -115,9 +113,7 @@ services:
115113
## Start - Eureka Service Discovery definition
116114
eureka:
117115
build: store-cloud-infra/eureka-server
118-
ports:
119-
- "8761:8761"
120-
restart: always
116+
restart: on-failure
121117
## End - Eureka Service Discovery definition
122118

123119
## Start - Edge Server definition
@@ -127,6 +123,8 @@ services:
127123
- "8080:8080"
128124
environment:
129125
- SPRING_PROFILES_ACTIVE=docker
126+
depends_on:
127+
- eureka
130128
restart: on-failure
131129
## End - Edge Server definition
132130
# End - Cloud Infrastructure

docker-compose-partitions.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ services:
8282
## Start - Store service definition
8383
store:
8484
build: store-services/store-service
85-
ports:
86-
- "8080:8080"
8785
environment:
8886
- SPRING_PROFILES_ACTIVE=docker
8987
- SPRING_CLOUD_STREAM_BINDINGS_OUTPUT-PRODUCTS_PRODUCER_PARTITION-KEY-EXPRESSION=payload.key
@@ -101,8 +99,6 @@ services:
10199
## Start - Eureka Service Discovery definition
102100
eureka:
103101
build: store-cloud-infra/eureka-server
104-
ports:
105-
- "8761:8761"
106102
restart: always
107103
## End - Eureka Service Discovery definition
108104

@@ -113,6 +109,8 @@ services:
113109
- "8080:8080"
114110
environment:
115111
- SPRING_PROFILES_ACTIVE=docker
112+
depends_on:
113+
- eureka
116114
restart: on-failure
117115
## End - Edge Server definition
118116
# End - Cloud Infrastructure

docker-compose.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ services:
3636
## Start - Store service definition
3737
store:
3838
build: store-services/store-service
39-
ports:
40-
- "8080:8080"
4139
environment:
4240
- SPRING_PROFILES_ACTIVE=docker
4341
depends_on:
@@ -49,8 +47,6 @@ services:
4947
## Start - Eureka Service Discovery definition
5048
eureka:
5149
build: store-cloud-infra/eureka-server
52-
ports:
53-
- "8761:8761"
5450
restart: on-failure
5551
## End - Eureka Service Discovery definition
5652

@@ -61,6 +57,8 @@ services:
6157
- "8080:8080"
6258
environment:
6359
- SPRING_PROFILES_ACTIVE=docker
60+
depends_on:
61+
- eureka
6462
restart: on-failure
6563
## End - Edge Server definition
6664
# End - Cloud Infrastructure

store-cloud-infra/edge-server/src/main/resources/application.yml

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,46 @@ spring:
55
# It is recommended switching to BlockingLoadBalancerClient instead.
66
cloud:
77
loadbalancer.ribbon.enabled: false
8+
# Route definitions of the system
89
gateway.routes:
9-
- id: host_route_200
10-
uri: http://httpstat.us
10+
- id: store-products
11+
# lb:// is used to direct Spring Cloud Gateway to use the client-side load balancer
12+
# to look up the destination in the discovery service.
13+
uri: lb://store
1114
predicates:
12-
- Host=i.feel.lucky:8080
13-
- Path=/headerrouting/**
14-
filters:
15-
- SetPath=/200
15+
- Path=/store/**
1616

17-
- id: host_route_418
18-
uri: http://httpstat.us
17+
- id: eureka-api
18+
uri: http://${app.eureka-server}:8761
1919
predicates:
20-
- Host=im.a.teapot:8080
21-
- Path=/headerrouting/**
20+
- Path=/eureka/api/{segment}
2221
filters:
23-
- SetPath=/418
22+
- SetPath=/eureka/{segment}
2423

25-
- id: host_route_501
26-
uri: http://httpstat.us
24+
- id: eureka-web-start
25+
uri: http://${app.eureka-server}:8761
2726
predicates:
28-
- Path=/headerrouting/**
27+
- Path=/eureka/web
2928
filters:
30-
- SetPath=/501
29+
- SetPath=/
30+
31+
- id: eureka-web-other
32+
uri: http://${app.eureka-server}:8761
33+
predicates:
34+
- Path=/eureka/**
3135

3236
app.eureka-server: localhost
3337

3438
eureka:
39+
instance:
40+
lease-renewal-interval-in-seconds: 5
41+
lease-expiration-duration-in-seconds: 5
42+
prefer-ip-address: true
3543
client:
3644
healthcheck.enabled: true
3745
service-Url.defaultZone: http://${app.eureka-server}:8761/eureka/
3846
initial-instance-info-replication-interval-seconds: 5
3947
registry-fetch-interval-seconds: 5
40-
instance:
41-
lease-renewal-interval-in-seconds: 5
42-
lease-expiration-duration-in-seconds: 5
4348

4449
ribbon:
4550
server-list-refresh-interval: 5000
@@ -60,4 +65,8 @@ logging.level:
6065
---
6166
spring.profiles: docker
6267

63-
app.eureka-server: eureka
68+
eureka:
69+
instance:
70+
prefer-ip-address: false
71+
72+
app.eureka-server: eureka

store-cloud-infra/edge-server/src/test/java/com/siriusxi/cloud/infra/gateway/EdgeServerApplicationTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33
import org.junit.jupiter.api.Test;
44
import org.springframework.boot.test.context.SpringBootTest;
55

6+
import static org.junit.jupiter.api.Assertions.assertTrue;
67
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
78

89
@SpringBootTest(
910
webEnvironment = RANDOM_PORT,
1011
properties = {"eureka.client.enabled: false"})
12+
// TODO add test cases https://spring.io/guides/gs/gateway/
1113
class EdgeServerApplicationTests {
1214

1315
@Test
1416
void contextLoads() {
15-
assert true;
17+
assertTrue(true);
1618
}
1719
}

store-cloud-infra/eureka-server/src/main/resources/application.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ server.port: 8761
99

1010
logging.level:
1111
com.netflix:
12-
eureka: OFF
13-
discovery: OFF
12+
eureka: debug
13+
discovery: debug
1414

1515
eureka:
1616
environment: Development

store-services/product-service/src/main/resources/application.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,15 @@ app:
7373

7474
# Service discovery configs
7575
eureka:
76+
instance:
77+
lease-renewal-interval-in-seconds: 5
78+
lease-expiration-duration-in-seconds: 5
79+
prefer-ip-address: true
7680
client:
7781
healthcheck.enabled: true
7882
service-url.defaultZone: http://${app.eureka-server}:8761/eureka/
7983
initial-instance-info-replication-interval-seconds: 5
8084
registry-fetch-interval-seconds: 5
81-
instance:
82-
lease-renewal-interval-in-seconds: 5
83-
lease-expiration-duration-in-seconds: 5
8485

8586
# This is a docker specific profile properties
8687
# Also profiles could be separated in its owen file
@@ -92,6 +93,10 @@ spring:
9293

9394
server.port: 8080
9495

96+
eureka:
97+
instance:
98+
prefer-ip-address: false
99+
95100
app:
96101
eureka-server: eureka
97102
database:

store-services/recommendation-service/src/main/resources/application.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,15 @@ app:
7272

7373
# Service discovery configs
7474
eureka:
75+
instance:
76+
lease-renewal-interval-in-seconds: 5
77+
lease-expiration-duration-in-seconds: 5
78+
prefer-ip-address: true
7579
client:
7680
healthcheck.enabled: true
7781
service-url.defaultZone: http://${app.eureka-server}:8761/eureka/
7882
initial-instance-info-replication-interval-seconds: 5
7983
registry-fetch-interval-seconds: 5
80-
instance:
81-
lease-renewal-interval-in-seconds: 5
82-
lease-expiration-duration-in-seconds: 5
8384

8485
# This is a docker specific profile properties
8586
# Also profiles could be separated in its owen file
@@ -92,6 +93,10 @@ spring:
9293
server:
9394
port: 8080
9495

96+
eureka:
97+
instance:
98+
prefer-ip-address: false
99+
95100
app:
96101
eureka-server: eureka
97102
database:

store-services/review-service/src/main/resources/application.yaml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,15 @@ management:
8888

8989
# Service discovery configs
9090
eureka:
91+
instance:
92+
lease-renewal-interval-in-seconds: 5
93+
lease-expiration-duration-in-seconds: 5
94+
prefer-ip-address: true
9195
client:
9296
healthcheck.enabled: true
9397
service-url.defaultZone: http://${app.eureka-server}:8761/eureka/
9498
initial-instance-info-replication-interval-seconds: 5
9599
registry-fetch-interval-seconds: 5
96-
instance:
97-
lease-renewal-interval-in-seconds: 5
98-
lease-expiration-duration-in-seconds: 5
99100

100101
# This is a docker specific profile properties
101102
# Also profiles could be separated in its owen file
@@ -109,6 +110,10 @@ spring:
109110

110111
server.port: 8080
111112

113+
eureka:
114+
instance:
115+
prefer-ip-address: false
116+
112117
app:
113118
eureka-server: eureka
114119
database:

store-services/store-service/src/main/java/com/siriusxi/ms/store/pcs/StoreServiceApplication.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,4 @@ public class StoreServiceApplication {
1515
public static void main(String[] args) {
1616
SpringApplication.run(StoreServiceApplication.class, args);
1717
}
18-
19-
@Bean
20-
@LoadBalanced
21-
public WebClient.Builder loadBalancedWebClientBuilder() {
22-
return WebClient.builder();
23-
}
2418
}

store-services/store-service/src/main/java/com/siriusxi/ms/store/pcs/config/StoreServiceConfiguration.java

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
package com.siriusxi.ms.store.pcs.config;
22

3-
import com.siriusxi.ms.store.pcs.integration.StoreIntegration;
4-
import org.springframework.beans.factory.annotation.Autowired;
53
import org.springframework.beans.factory.annotation.Value;
6-
import org.springframework.boot.actuate.health.CompositeReactiveHealthContributor;
7-
import org.springframework.boot.actuate.health.ReactiveHealthContributor;
8-
import org.springframework.boot.actuate.health.ReactiveHealthIndicator;
4+
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
95
import org.springframework.context.annotation.Bean;
106
import org.springframework.context.annotation.Configuration;
7+
import org.springframework.web.reactive.function.client.WebClient;
118
import springfox.documentation.builders.PathSelectors;
129
import springfox.documentation.service.ApiInfo;
1310
import springfox.documentation.service.Contact;
1411
import springfox.documentation.spring.web.plugins.Docket;
1512

16-
import java.util.Map;
17-
1813
import static java.util.Collections.emptyList;
1914
import static org.springframework.web.bind.annotation.RequestMethod.*;
2015
import static springfox.documentation.builders.RequestHandlerSelectors.basePackage;
@@ -23,8 +18,6 @@
2318
@Configuration
2419
public class StoreServiceConfiguration {
2520

26-
private final StoreIntegration integration;
27-
2821
@Value("${api.common.version}")
2922
private String apiVersion;
3023

@@ -52,33 +45,6 @@ public class StoreServiceConfiguration {
5245
@Value("${api.common.contact.email}")
5346
private String apiContactEmail;
5447

55-
@Autowired
56-
public StoreServiceConfiguration(StoreIntegration integration) {
57-
this.integration = integration;
58-
}
59-
60-
/**
61-
* This method is to check all the services health status, and store service health will be only
62-
* in up health state if and only if all of the core services and dependencies are up and running.
63-
*
64-
* @return ReactiveHealthContributor information about all the core microservices.
65-
*/
66-
@Bean(name = "Core Microservices")
67-
ReactiveHealthContributor coreServices() {
68-
69-
ReactiveHealthIndicator productHealthIndicator = integration::getProductHealth;
70-
ReactiveHealthIndicator recommendationHealthIndicator = integration::getRecommendationHealth;
71-
ReactiveHealthIndicator reviewHealthIndicator = integration::getReviewHealth;
72-
73-
Map<String, ReactiveHealthContributor> allIndicators =
74-
Map.of(
75-
"Product Service", productHealthIndicator,
76-
"Recommendation Service", recommendationHealthIndicator,
77-
"Review Service", reviewHealthIndicator);
78-
79-
return CompositeReactiveHealthContributor.fromMap(allIndicators);
80-
}
81-
8248
/**
8349
* Will exposed on $HOST:$PORT/swagger-ui.html
8450
*
@@ -120,4 +86,10 @@ Using the globalResponseMessage() method, we ask SpringFox not to add any defaul
12086
apiLicenseUrl,
12187
emptyList()));
12288
}
89+
90+
@Bean
91+
@LoadBalanced
92+
public WebClient.Builder loadBalancedWebClientBuilder() {
93+
return WebClient.builder();
94+
}
12395
}

0 commit comments

Comments
 (0)