one line of code at a time
Microservices with Spring Boot (Gateway, Discovery, Config server) 본문
Microservice Architecture is a software development approach that structures an application as a collection of loosely coupled small and independently deployables services.
Each service is designed to perform a specific function and communicates with other serivces through well-defined APIs or message broker.
This architecture style promotes modularity, flexibility, and scalability as each service can be developed, deployed, and maintained independently of the others.
Advantage
It allows faster release cycle and improved fault tolerance as a failure in one service does not necessarily affect the entire application. It also fosters the use of diverse technologies and programming languages for different services depending on their specific requirements and functionality.
Component

When user send the request, first entry point is API Gateway. It is responsible of intercepting and receiving all the request and redirect them to the correct service.
Of course we need micro services. Each microservice is communicating with database running on docker.
Trace all the request of your application using Zipkin.
Eureka (Discovery server) and Config (configuration) server. When microservice starts, it needs to register itself to discovery server.
Let's dive right into the project!
1. API Gateway
2. Discovery Server (Eureka)
3. Config Server
4. Microservices
5. Integrate Zipkin
1. API Gateway 에서 필요한 dependencies: Gateway, Eureka Discovery Client, Config Client, Spring Boot Actuator
2. Discovery Server: Eureka Server, Config Client, Spring Boot Actuator
3. Config Server: Config Server
4. Student Microservice: Lombok, PostgreSQL Driver, Spring Data JPA, Spring Web, Config Client, Eureka Discovery Client, Spring Boot Actuator
(School Microservice has the same dependencies)
Spring Eureka: http://localhost:8761/
discovery application을 실행시키고, student application 도 실행시키면 이렇게 뜬다.

schools 도 실행시키면 2개의 microservice가 뜨는 걸 볼 수 있다.

Communication between microservices
students와 schools 마이크로서비스 간 통신을 하기 위해 Open Feign이라는 패키지를 gradle에 추가해준다.
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'
처음에는 마이크로서비스 간에 direct로 Feign Client를 활용해서 데이터를 주고 받는데
나중에는 코드를 수정해서 Gateway를 통해서 통신을 할 수 있도록 구현했다.
Zipkin
zipkin을 통해서 로그를 trace 할 수 있다.
참고
'개발공부' 카테고리의 다른 글
| Docker Tutorial for Beginners 정리 (0) | 2024.08.09 |
|---|---|
| 컴퓨터 구조와 운영체제 50분만에 핵심 개념 정복하기 영상 정리 (0) | 2024.08.08 |
| 혼자 공부하는 네트워크 저자 50분 특강 정리 (0) | 2024.08.07 |