MSA
[MSA] Spring Boot - Netfix Eureka 란? 생성
차노도리
2023. 4. 4. 22:59
Netflix Eureka
- 넷플릭스에서 MSA를 위해 Spring Cloud에 기부한 오픈 소스이다.
- MSA에서 서비스들에 대한 정보를 저장하여 외부에서 서비스 호출 시 그에 맞는 서비스 서버로 전달해주는 미들웨어이다.
의존성 주입 (build.gradle)
// 스프링 클라우드 버전
ext {
set('springCloudVersion', "2021.0.6")
}
dependencies {
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-server'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
...
}
어플리케이션 부분에 유레카 서버 등록
- 어노테이션 추가
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@SpringBootApplication
@EnableEurekaServer
public class GugbabEurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(GugbabEurekaServerApplication.class, args);
}
}
프로젝트 설정값 변경 (application.yml)
- 자기 자신을 등록 안하기 위해 아래 값 false 설정
- register-with-eureka
- fetch-registry
server:
port: 7500
spring:
application:
name: gugbabeurekaserver
eureka:
client:
register-with-eureka: false
fetch-registry: false
service-url:
defaultZone: http://localhost:${server.port}/eureka/
실행 결과