Skip to content

Commit a44e611

Browse files
committed
Fix for aggregate course
1 parent ed402d4 commit a44e611

File tree

9 files changed

+66
-33
lines changed

9 files changed

+66
-33
lines changed

.idea/workspace.xml

+20-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build-images.sh

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
echo "Building Docker images for Kubernetes using Minikube..."
2+
3+
# Define an array of services
4+
SERVICES=(
5+
"microservices/course-composite-service:course-composite-service"
6+
"microservices/course-service:course-service"
7+
"microservices/review-service:review-service"
8+
"spring-cloud/gateway-service:gateway-service"
9+
)
10+
11+
eval $(minikube docker-env --profile microservice-deployment)
12+
13+
# Iterate over services and build each one
14+
for SERVICE in "${SERVICES[@]}"; do
15+
IFS=":" read -r DIR IMAGE <<< "$SERVICE"
16+
echo "Building $IMAGE..."
17+
cd "$DIR" || { echo "Failed to enter directory $DIR"; exit 1; }
18+
docker build -t "$IMAGE" .
19+
cd - >/dev/null || exit 1
20+
echo "$IMAGE built successfully!"
21+
done
22+
23+
echo "All images built successfully!"

microservices/course-composite-service/kubernetes/deployment.yml

+5-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ spec:
1616
spec:
1717
containers:
1818
- name: course-composite-service
19-
image: spring-boot-based-microservices-course-composite-service # Please rename these while building docker image
19+
image: course-composite-service # Please rename these while building docker image
2020
imagePullPolicy: IfNotPresent
2121
lifecycle:
2222
preStop:
@@ -25,5 +25,7 @@ spec:
2525
ports:
2626
- containerPort: 5000
2727
env:
28-
# - name: SPRING_DATASOURCE_URL
29-
# value: jdbc:postgresql://course-postgres/course_db
28+
- name: COURSE_SERVICE_URL
29+
value: http://course-service
30+
- name: REVIEW_SERVICE_URL
31+
value: http://review-service

microservices/course-composite-service/src/main/java/io/javatab/microservices/composite/course/web/CourseCompositeIntegration.java

+7-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import org.slf4j.LoggerFactory;
55
import org.springframework.beans.factory.annotation.Value;
66
import org.springframework.stereotype.Service;
7-
import org.springframework.web.client.RestTemplate;
87
import org.springframework.web.reactive.function.client.WebClient;
98
import reactor.core.publisher.Mono;
109

@@ -13,27 +12,27 @@
1312
@Service
1413
public class CourseCompositeIntegration {
1514

16-
private static final Logger LOG = LoggerFactory.getLogger(CourseCompositeIntegration.class);
15+
private static final Logger logger = LoggerFactory.getLogger(CourseCompositeIntegration.class);
1716

1817
private final String courseServiceUrl;
1918
private final String reviewServiceUrl;
2019
private final WebClient webClient;
2120

2221
public CourseCompositeIntegration(
23-
@Value("${app.course-service.host}") String courseServiceHost,
24-
@Value("${app.course-service.port}") String courseServicePort,
25-
@Value("${app.review-service.host}") String reviewServiceHost,
26-
@Value("${app.review-service.port}") String reviewServicePort,
22+
@Value("${app.course-service.uri}") String courseServiceUrl,
23+
@Value("${app.review-service.uri}") String reviewServiceUrl,
2724
WebClient.Builder webClient
2825
) {
2926
this.webClient = webClient.build();
30-
courseServiceUrl = "http://" + courseServiceHost + ":" + courseServicePort;
31-
reviewServiceUrl = "http://" + reviewServiceHost + ":" + reviewServicePort;
27+
this.courseServiceUrl = courseServiceUrl;
28+
this.reviewServiceUrl = reviewServiceUrl;
3229
}
3330

3431
public Mono<CourseAggregate> getCourseDetails(Long id) {
3532
String courseUrl = courseServiceUrl + "/api/courses/" + id;
3633
String reviewUrl = reviewServiceUrl + "/api/reviews?course=" + id;
34+
logger.info("Course URL ===> {}", courseUrl);
35+
logger.info("Review URL ===> {}", reviewUrl);
3736
Mono<Course> courseMono = webClient.get()
3837
.uri(courseUrl)
3938
.retrieve()

microservices/course-composite-service/src/main/resources/application.yml

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
app:
2+
23
course-service:
3-
host: localhost
4-
port: 9001
4+
uri: ${COURSE_SERVICE_URL:http://localhost:9001}
5+
56
review-service:
6-
host: localhost
7-
port: 9002
7+
uri: ${REVIEW_SERVICE_URL:http://localhost:9002}
88
spring:
99
application:
1010
name: course-composite-service
@@ -23,8 +23,6 @@ server:
2323
port: 8080
2424
app:
2525
course-service:
26-
host: course
27-
port: 8080
26+
uri: http://course:8080
2827
review-service:
29-
host: review
30-
port: 8080
28+
uri: http://review:8080

microservices/course-service/kubernetes/deployment.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ spec:
1616
spec:
1717
containers:
1818
- name: course-service
19-
image: spring-boot-based-microservices-course
19+
image: course-service
2020
imagePullPolicy: IfNotPresent
2121
lifecycle:
2222
preStop:

microservices/course-service/src/main/java/io/javatab/microservices/core/course/web/CourseController.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ public Course getById(@PathVariable Long id) {
4444
}
4545

4646
/*
47-
* http POST :9001/api/courses title="Microservices with Spring Boot" author="John Doe" price:=29.79 publisher="Manning"
47+
* http POST :9001/api/courses title="Microservices with Spring Boot" author="John Doe" price:=29.79 publisher="GitHub"
48+
* http POST :9001/api/courses title="Spring Boot in Action" author="John Doe" price:=69.45 publisher="GitHub"
4849
* */
4950
@PostMapping
5051
@ResponseStatus(HttpStatus.CREATED)

microservices/review-service/kubernetes/deployment.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ spec:
1616
spec:
1717
containers:
1818
- name: review-service
19-
image: spring-boot-based-microservices-review
19+
image: review-service
2020
imagePullPolicy: IfNotPresent
2121
lifecycle:
2222
preStop:

spring-cloud/gateway-service/kubernetes/deployment.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ spec:
1616
spec:
1717
containers:
1818
- name: gateway-service
19-
image: spring-boot-based-spring-cloud-gateway-service
19+
image: gateway-service
2020
imagePullPolicy: IfNotPresent
2121
lifecycle:
2222
preStop:

0 commit comments

Comments
 (0)