Spring Boot Microservices PPT Notes in PDF
Spring Boot Microservices PPT Notes in PDF
Employee
Service
React
App AP
Department
Gateway Service
Organizatio
Service
I
Employee Department
Service Service
Microservice 2
Microservice 1
Http Request
Department
Employee
Service
Service
Http Response
Asynchronous Communication
1. The client sends a request and does not wait for a response from the service
2. The client will continue executing it’s task - It don’t wait for the response
from the service
Message Message
Department
Employee Queue
Service
Service
Microservices Communicatio
3 Different Ways
Microservice 1
1. RestTemplat Queue Microservice 2
2. WebClien
3. Spring Cloud OpenFeign
Employee Department
Service Service
t
Microservice 1 Microservice 2
Http Request
Employee Department
Service Service
Http Response
Requirements
1. Consider Employee belongs to department and employee
has a unique department code
2. Change Get Employee REST API to return Employee
along with it’s department in response.
Development Steps
1. Add departmentCode eld in Employee JPA Entit
2. Create DepartmentDto clas
3. Con gure RestTemplate as Spring Bea
4. Inject and use RestTemplate to make REST API call in
EmployeeServiceImpl class
fi
fi
s
Microservice 1 Microservice 2
Http Request
Employee Department
Service Service
Http Response
Development Steps
1. Add Spring WebFlux Dependenc
2. Con gure WebClient as Spring Bea
3. Inject and Use WebClient to Call the REST AP
4. Test using Postman Client
fi
y
Microservice 1 Microservice 2
Http Request
Employee Department
Service Service
Http Response
Development Steps
1. Add Spring cloud open feign Maven dependency to
Employee-Servic
2. Enable Feign Client using @EnableFeignClient
3. Create Feign API Clien
4. Change the getEmployeeById method to use APIClien
5. Test using Postman Client
e
Service
Registry
fl
x
fl
Development Steps
1. Create Spring boot project as Microservice (service-registry
2. Add @EnableEurekaServer annotatio
3. Disable Eureka Server as Eureka Clien
4. Launch Eureka Server (Demo
5. Registering Department-Service Microservice as Eureka Clien
6. Run department-service Eureka Client (Demo
7. Registering Employee-Service Microservice as Eureka Clien
8. Run employee-service Eureka Client (Demo
9. Multiple Instances of Department-Service
)
API Gateway
1. API Gateway provides a uni ed interface for a set
of microservices so that clients no need to know
about all the details of microservices internals
2. API Gateway centralize cross-cutting concerns like
security, monitoring, rate limiting et
3. Spring Cloud provides Spring Cloud Gateway to
create API Gateway fi
c
API Gateway
Spring Cloud Gateway
Employee
Service
Client AP
Gateway
Department
Service
I
Development Steps
1. Create Spring boot project as Microservice (api-
gateway
2. Register API-Gateway as Eureka Client to
Eureka Server (Service Registry
3. Con guring API Gateway Routes and Test
using Postman Client
fi
)
fi
fi
fi
Spring Cloud Con g Server
Spring Clou
Con g Server
Register as con g client
Department
Service
fi
fi
fi
fi
Development Steps
1. Create Spring boot project as Microservice
(con g-server
2. Register Con g-Server as Eureka Clien
3. Set up Git Location for Con g Serve
4. Refactor Department-Service to use Con g Serve
5. Refactor Employee-Service to use Con g Serve
6. Refresh Use case
fi
fi
)
fi
r
fi
t
fi
r
fi
fi
fi
Problem using Spring Cloud Config Server
1. In order to reload the con g changes in Con g Client
applications (department-service and employee-service),
we need to trigger /refresh endpoint manually. This is not
practical and viable if you have large number of
applications
2. Spring Cloud Bus module provides a solution
3. Spring Cloud Bus module can be used to link multiple
applications with a message broker and we can broadcast
con guration changes.
fi
.
fi
fi
.
Subscribe
Employee
Service
Messag
Broker
Spring Clou
Con g Server
Department
Subscribe
Service Register as con g client
fi
e
fi
fi
Development Steps
1. Add spring-cloud-starter-bus-amqp dependency to department-
service and employee-servic
2. Install RabbitMQ using Docke
3. RabbitMQ con guration in application.properties of department-
service and employee-servic
4. Create Simple REST API in employee-servic
5. Change department-service and employee-service properties le and
call /busrefres
6. Demo
h
fi
e
fi
Distributed Tracing
Spring Cloud Slueth
Spring Cloud Slueth Spring Cloud Slueth
Department
API Employee
Client Service
Gateway Service
Development Steps
1. Implementing Distributed Tracing using
Spring Cloud Sleuth Librar
2. Using Zipkin to Visualize Trace Information
through UI
Development Steps
1. Add dependencie
2. Using @CircuitBreaker annotation to a method
(it is calling to external service
3. Fallback method implementatio
4. Add Circuit Breaker con guration in
application.properties l
5. Restart employee-service and demo
s
fi
fi
e
Department
API Employee
Client Service
Gateway Service
Retry Pattern
Development Steps
1. Using @Retry annotation to a method (it is
calling to external service
2. Fallback method implementatio
3. Add Retry con guration in
application.properties l
4. Restart employee-service and demo
fi
fi
e
Ports
App name: API-GATEWAY - Port: 9191
fi
I
Requirements
Client want’s employee, department and organization details in a
response
axios Employee
React App API Service
Gateway
Organizatio
Service
Development Steps
1. Create React App using Create React App Tool
2. Adding Bootstrap in React Using NPM
3. Connecting React App with API-Gateway
(REST API Call
4. Develop a React Component to Display User,
Department and Organization Details
5. Run React App and Demo
)
order_stock
Kafka Broker OrderEvent
Stock Service
Consume
Group 1
Order Service
Topic
OrderEvent
Consume
Email Service Group 2
Microservice 1
OrderEvent
Microservice 3
r
order_stock Order
Orde
Order Service Exchange Queue Stock Service
Order
order_email
Order
Microservice 1 Email
Email Service
Queue
Microservice 3
r
fi