본문 바로가기
Back-end/Spring Cloud (MSA)

Spring Cloud (MSA) - Config Server

by javapp 자바앱 2022. 11. 25.
728x90

 

마이크로 서비스 개발 시작

 

Dynamic Scaled Up And Down

  • Naming Server (Eureka)
  • Ribbon (Client Side Load Balancing)
  • Feign (Easier REST Clients)

 

Visibility And Monitoring

  • Zipkin Distributed Tracing
  • Netflix API Gateway

 

Ports

ApplicationPort

Application Port
Limits Service 8080, 8081, ...
Spring Cloud Config Server 8888
Currency Exchange Service 8000, 8001, 8002, ..
Currency Conversion Service 8100, 8101, 8102, ...
Netflix Eureka Naming Server 8761
Netflix Zuul API Gateway Server 8765
Zipkin Distributed Tracing Server 9411

 

 

URLs

Application URL
Limits Service http://localhost:8080/limits http://localhost:8080/actuator/refresh (POST)
Spring Cloud Config Server http://localhost:8888/limits-service/default http://localhost:8888/limits-service/dev
Currency Converter Service - Direct Call http://localhost:8100/currency-converter/from/USD/to/INR/quantity/10
Currency Converter Service - Feign http://localhost:8100/currency-converter-feign/from/EUR/to/INR/quantity/10000
Currency Exchange Service http://localhost:8000/currency-exchange/from/EUR/to/INR http://localhost:8001/currency-exchange/from/USD/to/INR
Eureka http://localhost:8761/
Zuul - Currency Exchange & Exchange Services http://localhost:8765/currency-exchange-service/currency-exchange/from/EUR/to/INR http://localhost:8765/currency-conversion-service/currency-converter-feign/from/USD/to/INR/quantity/10
Zipkin http://localhost:9411/zipkin/
Spring Cloud Bus Refresh http://localhost:8080/actuator/bus-refresh (POST)

 


 

Spring Cloud 

마이크로서비스의 개발, 배포, 운영에 필요한 아키텍처를 쉽게 구성할 수 있도록 지원하는. Spring Boot기반의 프레임워크

  • Ribbon 대신 Spring Cloud LoadBalancer 사용
  • Zuul 대신 Spring Cloud Gateway 사용

 

도커 사용 예

 

 

 

Config Server 연습

 

Start Spring Cloud Config Server

Dependencies

  • Spring Boot Dev Tools
  • Config Server

application.properties

spring.application.name=spring-cloud-config-server
server.port=8888
spring.cloud.config.server.git.uri=file:///c:/Users/Admin/Desktop/Main/dev/spring/newSpring/SpringMSA/git-localconfig-repo

 

 

깃 생성

mkdir git-localconfig-repo
cd git-localconfig-repo
git init

git add *
git commit -m "adding limits-service.properties"

Config Server에서 조회

중요한 점

  • git repo 에 생성된 properties 파일명이 Config Server 명(limits-service)이 된다.

 

 


 

 

Limits Microservice

Limits

public class Limits
{
    private int minimum;
    private int maximim;

    public Limits() {
    }

    public Limits(int minimum, int maximim) {
        this.minimum = minimum;
        this.maximim = maximim;
    }

    public int getMinimum() {
        return minimum;
    }

    public void setMinimum(int minimum) {
        this.minimum = minimum;
    }

    public int getMaximim() {
        return maximim;
    }

    public void setMaximim(int maximim) {
        this.maximim = maximim;
    }
}

 

Configuration

@Component
@ConfigurationProperties("limits-service")
public class Configuration
{
    private int minimum;
    private int maximum;

    public int getMinimum() {
        return minimum;
    }

    public void setMinimum(int minimum) {
        this.minimum = minimum;
    }

    public int getMaximum() {
        return maximum;
    }

    public void setMaximum(int maximum) {
        this.maximum = maximum;
    }
}

 

LimitsController

@RestController
public class LimitsController
{
    @Autowired
    private Configuration configuration;

    @GetMapping("/limits")
    public Limits retrieveLimits()
    {
        return new Limits(configuration.getMinimum(), configuration.getMaximum());
    }

}

 

application.properties

spring.application.name=limits-service
spring.config.import=optional:configserver:http://localhost:8888

limits-service.minimum=3
limits-service.maximum=997
  • git repo 에 생성된 properties 파일명이 Config Server 명(limits-service)이 된다.
  • config server  url 등록

git repo에 있는 limits-service.properties 를 읽어온다.

 

config server 페칭

limits-service 실행

 

 

profile 변경

repo에 dev, qa 추가

 

spring.application.name=limits-service
spring.config.import=optional:configserver:http://localhost:8888

spring.profiles.active=dev
spring.cloud.config.profile=dev
#spring.cloud.config.name=

limits-service.minimum=3
limits-service.maximum=997

limits-service의 profile과

config의 profile을 dev로 설정

 

 

limits-service 실행시 profiles 가 dev로 설정됨

 

Config Server

http://localhost:8888/limits-service/dev

dev properties 확인 가능

 

 

 

댓글