Actuator 를 활용하여 Spring 서버를 재기동하지 않고도 서버를 재시작할 수 있게 되었다. 하지만, 여러 마이크로서비스를 사용할 경우 일일이 서버에 POST 요청을 보내 환경 변수를 업데이트할 필요가 있다.
Spring Cloud Bus 를 활용하면 모든 서비스에 일일이 요청할 필요없이 한개의 서비스에 요청하는 것으로 모든 서버의 환경변수 업데이트 요청을 전파할 수 있다.
RabbitMQ 설치
Window 환경에서 Chocolatey 를 이용하여 RabbitMQ 설치
choco install rabbitmq
콘솔에서 C:\Program Files\RabbitMQ Server\rabbitmq_server-3.13.4\sbin
의 RabbitMQ 실행 위치로 이동
RabbitMQ Management Plugin Enable
콘솔이동 후 명령어 사용
rabbitmq-plugins enable rabbitmq_management
dependency 추가 (config-server 및 다른 애플리케이션 모두)
// https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-bus-amqp
implementation 'org.springframework.cloud:spring-cloud-starter-bus-amqp'
application.yml
변경 (RabbitMQ 연결)
spring:
rabbitmq:
host: 127.0.0.1
port: 5672
username: guest # RabbitMQ default username
password: guest # RabbitMQ default password
application.yml
변경 (busrefresh 추가)
management:
endpoints:
web:
exposure:
include: health, refresh, beans, busrefresh
busrefresh
경로를 통해 환경 변수 변경 적용사용할 환경 변수 지정 (bootstrap.yml
)
동일한 환경 변수를 사용할 서비스들을 지정
spring:
cloud:
config:
name: config-server
uri: http://127.0.0.1:8888
현재 config-server 의 외부 application.yml
file:///${user.home}/native-file-repo/application.yml
token:
expiration_time: 86500000
secret: token-secret
gateway:
ip: 192.168.0.15
http://localhost:{port}/actuator/busrefresh 에 POST 요청을 하여 연결된 모든 마이크로 서비스의 환경 정보를 업데이트