미니미 MSA 세팅하기

veluga·2022년 6월 27일
0

MSA

목록 보기
3/5

Eureka - registry server

dependency

dependencies {
	implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-server'
	developmentOnly 'org.springframework.boot:spring-boot-devtools'
	testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

config

server:
  port: 8761
#  address: 127.0.0.1

spring:
  application:
    name: registry-server
eureka:
  instance:
    hostname: localhost
    prefer-ip-address: true
#    ip-address: ${server.address}
    instance-id: ${spring.application.name}:${spring.application.intance_id:${server.port}}
  client:
    service-url:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
      register-whit-eureka: false
      fetch-registry: false

유레카서버로서 동작하게 어노테이션 추가

Gateway - spring cloud gateway

dependency

dependencies {
	implementation 'org.springframework.boot:spring-boot-starter-actuator'
	implementation 'org.springframework.boot:spring-boot-starter-web'
//	implementation 'org.springframework.boot:spring-boot-starter-webflux'
	implementation 'org.springframework.cloud:spring-cloud-starter-gateway'
	implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-server'
	compileOnly 'org.projectlombok:lombok'
	annotationProcessor 'org.projectlombok:lombok'
	testImplementation 'org.springframework.boot:spring-boot-starter-test'
	testImplementation 'io.projectreactor:reactor-test'
}

유레카 서버 디펜던시
actuator 추가하여 endpoint 확인 및 healthcheck

config

server:
  port: 8080
#  address: 127.0.0.1

eureka:
  instance:
    hostname: localhost
    prefer-ip-address: true
#    ip-address: ${server.address}
    instance-id: ${spring.application.name}:${spring.application.intance_id:${server.port}}
  client:
    register-with-eureka: true
    fetch-registry: true
    service-url:
      defaultZone: http://localhost:8761/eureka

management:
  endpoint:
    gateway:
      enabled: true

  endpoints:
    web:
      exposure:
        include: "*"

spring:
  main:
    web-application-type: reactive
  application:
    name: apigateway-service
  cloud:
    gateway:
      discovery:
        locator:
#          유레카 서비스로 받은 서비스 등록정보로 경로를 동적 생성
          enabled: true
          lower-case-service-id: true
      metrics:
        enabled: true
#      httpclient:
#        proxy:
#          host: localhost
      routes:
        - id: sample-api
          uri: lb://SAMPLE-API
          predicates:
            - Path=/sample-api/**

유레카 클라이언트로서 동작하게 어노테이션 추가

Service - smpl api server

테스트용 spring boot api server

gateway와 마찬가지로 클라이언트로 등록해준다.

Test

  1. gateway 에서 특정 경로 호출
  2. 해당 경로의 서비스를 유레카에서 검색
  3. 해당 서비스로 라우팅
  4. 해당 서비스의 api call 성공

profile
애개 (애기개발자)

0개의 댓글