코딩박스

[Spring] Discovery Server (Eureka Server) 란 ?

by 코박7

discovery server 의 흐름.

  1. Eureka Client 서비스가 시작 될 때 Eureka Server에 자신의 정보를 등록한다.
  2. Eureka Client는 Eureka Server로 부터 다른 Client의 연결정보가 등록되어 있는 Registry를 받고 자신의 Local에 저장하게 된다.
  3. 30초 마다 Eureka Server로 부터 변경 사항을 갱신받는다.
  4. 30초 마다 ping을 통하여 자신이 동작하고 있다는 신호를 보낸다. 신호를 보내지 못하면 Eureka Server가 보내지 못한 Client를 Registry에서 제외시킨다.
  • Eureka Server 는 Eureka Client를 관리하는 서버이다.

 

의존성 추가 및 설정

buildscript {
    ext {
        set('springCloudVersion', "2021.0.4")
    }
}

plugins {
    id 'java'
    id 'org.springframework.boot' version '2.7.12'
    id 'io.spring.dependency-management' version '1.0.15.RELEASE'
}

version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenCentral()
}

dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
    }
}

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

tasks.named('test') {
    useJUnitPlatform()
}

jar {
    enabled = false
}
// application 에 @EnableEurekaServer 어노테이션 등록

@SpringBootApplication
@EnableEurekaServer
public class DiscoveryApplication {

    public static void main(String[] args) {
        SpringApplication.run(DiscoveryApplication.class, args);
    }

}
server.port=8761

# register-with-eureka: eureka에 등록여부를 정한다. 이 서버는 본인 자신이기에 등록하지 않는다.
eureka.client.register-with-eureka=false
# fetch-registry: registry의 항목을 로컬로 캐시할것인지 정한다.
eureka.client.fetch-registry=false
# eureka service 의 인스턴스 호스트 이름을 설정.
eureka.instance.hostname= eurekaserver
# 일시적인 네트워크 장애로 인한 서비스 해제 막기 위한 자기 보호 모드
# false 설정 시 하트비트가 들어오지 않으면 바로 서비스를 제거한다.
eureka.server.enable-self-preservation=true
  • properties 추가.

 

 

블로그의 정보

코딩박스

코박7

활동하기