Eureka란?
Service Discovery: 외부에서 MSA를 검색하기 위해 사용되는 개념, client의 요청 정보에 따라서 필요한 msa의 위치를 알려주는 역할
[Service(MSA) 등록, 검색하는 기능]
동작 순서
1. MSA의 위치정보를 eureka server에 등록
2. MSA를 사용할 Client가 요청정보를 API 게이트웨이(Load balancer)에 전달
3. 요청 정보가 Service Discovery에 전달되어 Client가 필요한 정보가 어디에 있는지 Client에게 반환
4. Client의 요청 정보가 MSA를 호출하고 응답을 받음
프로젝트 생성
1. Eureka Server 프로젝트
- dependency : Eureka Server 추가
- Application에 @EnableEurekaServer 어노테이션 붙이기
- application.yml 파일에 기본 설정하기
register-with-eureka : eureka에 등록여부를 설정한다. 이 프로젝트에서는 eureka 서버 본인이므로 등록하지 않는다.
fetch-registry : registry의 항목을 로컬로 캐시할것인지 설정한다. (필요 없으므로 하지 않음)
- Run 으로 실행 후 localhost:8081 접속
2. Eureka Client
- dependency : Eureka Discovery Client, Spring Web 추가 (Spring Web 없으면 Run 실행 시 에러 발생)
Field optionalArgs in org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration required a bean of type 'com.netflix.discovery.AbstractDiscoveryClientOptionalArgs' that could not be found.
- Application에 @EnableEurekaClient 어노테이션 붙이기
- application.yml 파일에 기본 설정하기
service-url.defaultZone : eureka server의 위치 지정
- Run 으로 실행 후 localhost:8081 접속
Instances cirurrently registered with Eureka 부분을 보면 등록된 eureka-client-service:8082 를 확인할 수 있다.
up은 동작중이라는 상태를 의미함
'스프링' 카테고리의 다른 글
[Spring] Spring Cloud Gateway 사용법 (0) | 2023.01.01 |
---|---|
[Spring] Spring Cloud Netflix Eureka (1개의 PC에서 여러 인스턴스 등록하기) (0) | 2022.12.29 |
[Spring] ServletUriComponentsBuilder 사용하여 사용자에게 URI 전달하기 (0) | 2022.10.10 |
[Spring] ResponseEntity 에 대하여 (0) | 2022.10.10 |
@RequestBody 란 (0) | 2022.10.09 |