This guide explains how to set up a Spring Boot microservices architecture with various features like Service Registry, Service Discovery, Communication between microservices, API Gateway, Config Server and Client, and Fault Tolerance.
- Create different Spring Boot applications for each microservice.
- Add dependencies such as Cloud Bootstrap and Eureka Server.
- Add @EnableEurekaServer annotation on the main method.
- Configure application.yml file.
- Add dependency Eureka Discovery Client.
- Add @EnableEurekaClient annotation on the main method.
- Configure application.yml file.
- Use Rest Template in UserService.
- Remove Host and Port by adding @LoadBalanced on a configuration bean. This allows using the service name instead of the port number.
- Add dependency OpenFeign in pom.xml.
- Add @EnableFeignClients annotation on the main method.
- Create one service, for example, HotelService interface with @FeignClient annotation and having method definition.
- Add dependencies such as Cloud Bootstrap, Gateway, Spring Reactive Web, and Eureka Discovery Client.
- Add @EnableEurekaClient annotation on the main method.
- Configure application.yml file.
- Add dependencies such as Config Server and Eureka Discovery Client.
- Create one repository on Github and add new files (application-dev.yml, application-prod.yml, and application.yml).
- Add @EnableConfigServer annotation on the main method.
- Use http://192.168.1.67:8777/application/default to check whether property source data is present or not.
- Implement Config Client implementation to fetch implementation in other Spring Boot microservices.
- After adding the dependency to any microservice (Config Client), it will configure as client.
- Configure application.yml file with profiles active and config import to add different Github profiles to microservice.
Step 8: Handling Fault Tolerance (By Implementing Circuit Breaker using Resilience4J and Retry using Resilience4J)
- Add dependencies such as Actuator, AOP, and Resilience4J.
- Add @CircuitBreaker annotation to the APIs which are calling another services (or another Spring Boot application).
- Mention fallback method along with Circuit Breaker and add fallback method.
- Note: Parameters and return type must be the same for the original and fallback method.
- Configure Actuator and Resilience4J Configuration in application.yml file.
- Add dependencies such as Actuator, AOP, and Resilience4J.
- Add @Retry annotation to the APIs which are calling another services (or another Spring Boot application).
- Mention fallback method along with Circuit Breaker and add fallback method.
- Note: Parameters and return type must be the same for the original and fallback method.
- Configure Actuator and Retry Configuration in application.yml file.
- Add Dependencies ( Actuator, AOP and Resilience4J)
- Add @RateLimiter annotation to the API's which are calling another Services( or another spring boot application)
- Mention fall method along with CircuitBreaker and add Fallback method.
- Important: Parameters and return type must be the same for the original and fallback method.
- Configure RateLimiter Configuration in application.yml file
- Download Apache Jmeter to test performance both on static and dynamic resources.
- Extract Jmeter and go to bin and select jmeter and run the application.
- Go to Test Plan and add Thread (Users) as Thread Group and after that add the number of threads (Users)
- Now go to Thread Group and go to sampler and select Http request after that add SERVER Name or IP: localhost and Port Number (UserService)
- Add Http Request as (GET) path: (/users/354da100-43c0-468b-9663-c6a3196ef0cd)
- Now go to HttpRequest on the left-hand side and add Listener as View Result Tree to see the result.
- Now on the top, start the server and save ViewResult with some name.