service1.port : 9001
service2.port : 9002
service3.port : 9003
service4.port : 9004
...
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
...
@SpringBootApplication
@EnableDiscoveryClient
public class UserServiceApplication {
public static void main(String[] args) {
SpringApplication.run(UserServiceApplication.class, args);
}
}
server:
port: 9001
spring:
application:
name: user-service
#register-with-eureka : 서버로부터 인스턴스의 정보를 주기적으로 가져옴
eureka:
client:
register-with-eureka: true
fetch-registry: true
service-url:
defaultZone: <http://127.0.0.1:8761/eureka> # 현재 마이크로 서비스를 eureka에 등록함
Status : ipAddr:serviceName:portNumber
유레카를 통해 같은 서비스가 2개의 인스턴스로 구성되었음을 확인할 수 있다.
유레카는 G/W 혹은 LB에 실행되고 있는 인스턴스 정보를 제공한다.