Inflearn 의 'Spring Cloud로 개발하는 마이크로서비스 애플리케이션(MSA)-이도원 개발자님' 의 강의를 들으며 Automatic API Config Server를 공부하면서 배운것들을 정리/리마인드 겸, 또한 나중에 빠른 사용을 위한 Master Code를 남기기 위해 글을 올린다.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
spring:
cloud:
config:
uri: ${서버IP}:${server포트}
name:: ${가져올 yml 파일 이름}
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
/actuator/**
을 모두 접속가능하도록 한다.management:
endpoints:
web:
exposure:
include: refresh, health, beans, busrefresh, info, metrics, prometheus
include 내용은 공식 reference 들을 통해서 확인할 수 있다. refresh : post로 전송시, 해당 파일을 반영된 서버를 확인할 수 있다.// Client 가 요청했던 정보를 Memory에 담아서 저장한다.
// 이후에 httpTrace를 통해서 확인할 수 있다.
@Bean
public HttpTraceRepository httpTraceRepository() {
return new InMemoryHttpTraceRepository();
}
spring:
cloud:
gateway:
routes:
- id: ${SERVICE-ID}
uri: lb://${SERVICE-NAME-IN-EUREKA}
predicates:
- Path=/${SERVICE-URL}/actuator/**
- Method=GET,POST # GET과 POST를 둘다 사용할 수도 있음!
filters:
- RemoveRequestHeader=Cookie
- RewritePath=/user-service/(?<segment>.*), /$\{segment} # 해당되는 url을 재생성
→ 결론적으로 이렇게 사용하는것도 직접 하는것보다는 효율적이지만, 썩 편리하지는 않다!!
config service의 yml 파일 설정
# Master Config yml
spring:
application:
name: config-service
cloud:
config:
server:
# 파일시스템을 사용하는 경우 (Native)
native:
# Mac : file://${user.home}/${file Location}
# window : file:///${user.home}/${file Location}
search-locations: file:///${user.home}/{file location}
# Git을 사용하는경우
git:
# uri: file://{file location with absolute url} # local git을 가져오기
uri: https://github.com/yimo22/config.git # 원격에 있는 git으로 가져오기
# username: ${name} # 만약 private으로 된 경우, ID와 PW 입력
# password: ${password}
→ 모든 서버에 적용하기에는 다소 무리가 있다!
수백개의 Micro Service에 대해서는 모든 것을 refresh 시키기에는 번거롭다
—> 따라서 MS(Micro Service)가 효율적으로 변경되기 위해 Spring Cloud Bus 를 사용하여 관리한다
→ Kafka 가 좀더 대용량의 데이터를 처리할경우 적합, RabbitMQ는 좀더 작은 규모의 데이터를 처리할때 적합하다!
<!-- Spring Cloud Config 서버 사용을 위한 Library -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<!-- amqp 프로토콜을 사용하기 위한 Library -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
<version>2.7.13</version>
</dependency>
<!-- rebuilding 작업이 필요없이 설정을 위한 라이브러리 추가 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
<!-- actuator 추가 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>