The project provides the Netflix OSS integration to the Spring boot application through automatic configuration and is bound to the spring environment and other spring programming model idioms. With a few simple notes, you can quickly enable and configure common patterns in your application and build large distributed systems from tested Netflix components. The modes provided include service discovery (Eureka), Circuit breakers (Hystrix), intelligent routing (Zuul), and client load Balancing (Ribbon).
Service Discovery: Eureka Client
Service discovery is one of the key principles of micro-service architecture. Trying to configure each client or some form of convention can be very difficult and very fragile. The Netflix service discovers that servers and clients are Eureka. Servers can be configured and deployed as high availability, and each server replicates the state of the enrollment service to other servers.
How to include Eureka clients
To include the Eureka client in your project, use the initiator of group Org.springframework.cloud and artifact ID spring-cloud-starter-eureka. For more information about building a system using the current Spring Cloud publishing list settings.
Register Eureka
When a client registers Eureka, it provides metadata about itself, such as host and port, health indicator URL, home page, and so on. Eureka receives heartbeat messages from each instance belonging to the service. If a heartbeat failure exceeds a configurable timesheet, the instance is typically removed from the registry.
Example Eureka Client:
@Configurationbr/> @ComponentScan
@EnableEurekaClient
public class Application {
@RequestMapping("/")public String home() { return "Hello world";}public static void main(String[] args) { new SpringApplicationBuilder(Application.class).web(true).run(args);}
}
(That is, the fully normal spring boot application). In this example, we explicitly use @enableeurekaclient, but only Eureka is available, and you can use @enablediscoveryclient. Configuration is required to locate the Eureka server. Cases:
Application.yml
Eureka
Client
Serviceurl:
defaultzone:http://localhost:8761/eureka/
where "Defaultzone" is a magic string fallback value that provides a service URL for any client that does not represent a preference (that is, it is a useful default value).
The default application name (service ID) obtained from environment, the virtual host and the unsecured port are ${spring.application.name},${spring.application.name} and ${server.port respectively }。
@EnableEurekaClient the application into a Eureka "instance" (that is, registering itself) and a "client" (that is, it can query the registry to find other services). The instance behavior is driven by the eureka.instance.* configuration key, but if you make sure that your application has spring.application.name (which is the default value for the Eureka Service ID or VIP), the default value will be normal.
Spring Cloud Netflix