한마디로
좀 더 자세히 말한다면마디로
서비스 인스턴스 정보를 중앙 관리하고 Discovery 클라이언트를 통해 서비스 인스턴스 정보에 접근한다. 동일 서비스에 대해 둘 이상의 인스턴스를 등록할 수 있으며 클라이언트는 이를 통해 로드밸런싱을 구현할 수 있다.
Eureka Server (Service Registry)
maven
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
application.properties
spring.application.name=discovery-service
server.port=${PORT:8761}
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.server.enable-self-preservation=true
java
@SpringBootApplication
@EnableEurekaServer
public class DiscoveryServicerviceApplication {
public static void main(String[] args) {
SpringApplication.run(DiscoveryServicerviceApplication.class, args);
}
}
Eureka Dashboard UI
Urls
Configuration com.netflix.eureka.EurekaServerConfig com.netflix.eureka.DefaultEurekaServerConfig com.netflix.appinfo.EurekaInstanceConfig com.netflix.appinfo.AbstractInstanceConfig com.netflix.appinfo.InstanceInfo
Eureka Client (Service Producer)
maven
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
bootstrap.properties
spring.application.name=eureka-client
server.port=${PORT:8989}
eureka.instance.hostname=${vcap.application.uris[0]:localhost}
eureka.instance.nonSecurePort=80
eureka.instance.metadataMap.instanceId=${vcap.application.instance_id:${spring.application.name}:${spring.application.instance_id:${server.port}}}
eureka.instance.leaseRenewalIntervalInSeconds = 1
eureka.instance.lease-expiration-duration-in-seconds=5
eureka.instance.lease-renewal-interval-in-seconds=10
eureka.client.registryFetchIntervalSeconds = 5
https://github.com/Netflix/eureka/blob/master/eureka-client/src/main/java/com/netflix/appinfo/EurekaInstanceConfig.java https://github.com/Netflix/eureka/blob/master/eureka-client/src/main/java/com/netflix/discovery/EurekaClientConfig.java
java
@SpringBootApplication
//@EnableEurekaClient
@EnableDiscoveryClient
public class DiscoveryClientApplication {
public static void main(String[] args) {
SpringApplication.run(DiscoveryClientApplication.class, args);
}
}
VM Option
- -Dserver.port=8980
Configuration com.netflix.discovery.EurekaClientConfig com.netflix.discovery.DefaultEurekaClientConfig
Service Consumer
Java
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class DiscoveryClientApplication {
public static void main(String[] args) {
SpringApplication.run(DiscoveryClientApplication.class, args);
}
}
@FeignClient("http://user-service")
public interface UserServiceIntegration {
@RequestMapping(value = "/users/{userId}", method = RequestMethod.GET)
String getUser(@PathVariable("userId") String userId);
}
@RestController
@RequestMapping(value = "/accounts")
public class AccountController {
@Autowired
UserServiceIntegration userService;
@RequestMapping(value = "/{userId}", method = RequestMethod.GET)
public String getUser(@PathVariable String userId) {
String user = userService.getUser(userId);
return user;
}
}
참조
http://tech.asimio.net/2016/11/14/Microservices-Registration-and-Discovery-using-Spring-Cloud-Eureka-Ribbon-and-Feign.html http://callistaenterprise.se/blogg/teknik/2015/04/10/building-microservices-with-spring-cloud-and-netflix-oss-part-1/ http://callistaenterprise.se/blogg/teknik/2015/05/20/blog-series-building-microservices/ https://github.com/marceloserpa/marcelo_serpa_sandbox/tree/master/spring-cloud-eureka-poc https://github.com/joshlong/service-registration-and-discovery https://github.com/ewolff/microservice/tree/master/microservice-demo
http://blog.abhijitsarkar.org/technical/netflix-eureka/ https://www.todaysoftmag.com/article/1429/micro-service-discovery-using-netflix-eureka
주의
https://github.com/Netflix/eureka/wiki/Configuring-Eureka#configuration If you are running in the cloud environment, you will need to pass in the java commandline property -Deureka.datacenter=cloud so that the Eureka Client/Server knows to initialize the information specific to AWS cloud.
Client
https://github.com/Netflix/eureka/wiki/Configuring-Eureka#configuration The easiest way to configure Eureka client is by using property files. By default, Eureka client searches for the property file eureka-client.properties in the classpath. It further searches for environment specific overrides in the environment specific properties files. The environment is typically test or prod and is supplied by a -Deureka.environment java commandline switch to the eureka client (without the .properties suffix). Accordingly, the client also searches for eureka-client-{test,prod}.properties.
You can take a look at the examples here for default configurations. You can copy these configurations and edit for your need and place them in your class path. If you want to change the name of the properties file for some reason you can do so by specifying -Deureka.client.props= (without a suffix) in the java commandline switch, where is the name of the property file to search for for.
Server
Eureka Server has two sets of configurations
Eureka Client configuration as explained above. Eureka Server configuration. The easiest way to configure Eureka Server is by using property files similar to the Eureka Client above. First, configure the Eureka client that is running with the server as specified above. Eureka server itself fires up a Eureka Client that it uses to find other Eureka Servers. Therefore, you need to first configure the Eureka Client for the Eureka Server as you would do with any other clients that connect to the Eureka service. The Eureka Server will use its Eureka Client configuration to identify peer eureka server that have the same name (ie) eureka.name
After configuring the Eureka Client, you may need to configure the Eureka Server if you are running in AWS. Eureka server by default searches for property file eureka-server.properties in the classpath. It further searches for environment specific overrides in the environment specific properties files. The environment is typically test or prod and is supplied by a -Deureka.environment java commandline switch to the eureka server (without the .properties suffix). Accordingly the server also searches for eureka-server-{test,prod}.properties.