[Spring Cloud] Spring Cloud Bus

jsieon97·2023년 3월 16일
0

Spring Cloud Bus

  • 분산 시스템의 노드를 경량 메시지 브로커와 연결
  • 상태 및 구성에 대한 변경 사항을 연결된 노드에게 전달(Broadcast)

Config가 변경 되었을때

  • 서버 재기동
  • Actuator refresh
  • Spring Cloud Bus 사용
    • 분산 시스템의 노드를 경량 메시지 브로커와 연결
    • 상태 및 구성에 대한 변경 사항을 연결된 노드에게 전달 (Broadcast)

AMQP(Advanced Message Queuing Protocol)

  • 메시지 지향, 큐잉, 라우팅(P2P, Publisher-Subcriber), 신뢰성, 보안
  • Erlang, RabbitMQ에서 사용

Kafka 프로젝트

  • Apache Software Foundation이 Scalar 언어로 개발한 오픈 소스 메시지 브로커 프로젝트
  • 분산형 스트리밍 플랫폼
  • 대용량의 데이터를 처리 가능한 메시징 시스템

RabbitMQ와 Kafka

  • RabbitMQ
    • 메시지 브로커
    • 초당 20+ 메시지를 소비자에게 전달
    • 메시지 전달 보장, 시스템 간 메시지 전달
    • 브로커, 소비자 중심
  • Kafka
    • 초당 100K+ 이상의 이벤트 처리
    • Pub/Sub, Topic에 메시지 전달
    • Ack(메시지 확인)를 기다리지 않고 전달 가능(조절 가능)
    • 생산자 중심

Erlang, RabbitMQ, RabbitMQ management설치

RabbitMQ 설치과정은 생략

Dependencies 추가

  • ConfigService
    • AMQP for Spring Cloud Bus, Actuator
  • UserService, API Gateway
    • AMQP for Spring Cloud Bus
      spring-cloud-starter-bus-amqp

application.yml 수정

  • ConfigService, UserSerivce, API Gateway
// application.yml

spring:
  application:
    name: [서비스 이름]
  rabbitmq:
    host: 127.0.0.1
    port: 5672
    username: guest
    password: guest
	
...
  
management:
  endpoints:
    web:
      exposure:
        include: health, busrefresh

RabbitMQ가 연결 된 것을 확인할 수 있다.

ConfigService의 property를 수정하고 ConfigService와 연결된 서비스들의 bootstrap.yml파일을 수정

// bootstrap.yml

spring:
  cloud:
    config:
      uri: http://127.0.0.1:8888
      name: config-service

이렇게 지정하면 configservice에서 경로로 지정해둔 property파일을 configservice와 연결된 모든 서비스에서 같은 설정을 사용할 수 있다.

profiles 설정을 통해 연결된 상태에서 서로 다른 property파일을 적용할 수 있게 할 수도있다.

profile
개발자로써 성장하는 방법

0개의 댓글