Spring

[Spring Cloud] Spring Cloud Config Server - 3

dev_minpark 2024. 7. 18. 16:23

Config Server 의 Property 를 수정이 됐을때 각 연동된 서비스들은 어떻게해야 정보가 업데이트 될까?

해당 Config Property 를 업데이트 하기 위해 세가지 방법이 있다.

  • 서버 재기동 - 서비스를 재기동시키는건 Config 서버를 중앙화한 의미가 없어지게 된다.
  • Actuator Refresh
    • Application 상태, 모니터링
    • Metric 수집을 위한 Httpd End Point 제공
    • 이번 예제에서 사용
  • Spring Cloud Bus
    • 동적으로 Config 변경을 위한 MQ(Message Que) Handler

gradle 의존성 추가
WebSecurityConfig /actuator/** path 접근 허용 처리
actuator endpoints refresh, health, beans 추가

* https://docs.spring.io/spring-boot/reference/actuator/endpoints.html#page-title

 

Endpoints :: Spring Boot

If you add a @Bean annotated with @Endpoint, any methods annotated with @ReadOperation, @WriteOperation, or @DeleteOperation are automatically exposed over JMX and, in a web application, over HTTP as well. Endpoints can be exposed over HTTP by using Jersey

docs.spring.io

 

{server:port}/actuator 

활성화된 모든 actuator endpoint 확인 가능

 

우리의 목적은 config server 에서 광고중인 ecommerce.yml의 property 가 수정됐을때 동적으로 반영을 위해 actuator/refresh 를 이용한다.

 

POST /actuator/refresh 요청

다시 설정 정보를 가져오는 모습을 확인할 수 있다.

  • 단점 : 마이크로 서비스들을 일일히 refresh 요청을 수동으로 해줘야 함 (사실상 안쓰인다는 의미)