Follow me to learn spring Cloud Netflix client use

Source: Internet
Author: User

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 org.springframework.cloud spring-cloud-starter-eureka the initiator of the group and artifact IDs. for More information about using the current Spring Cloud Publishing list settings to build your system, see The Spring Cloud project page .

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:

@Configuration@ComponentScan@EnableAutoConfiguration@EnableEurekaClient@RestControllerpublic 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 available, you can also use @EnableDiscoveryClient . configuration is required to locate the Eureka server. Example:

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).

From Environment the default application name (service ID) obtained, the virtual host and the non-secure ports are ${spring.application.name} , respectively, ${spring.application.name} and ${server.port} .

@EnableEurekaClient The application goes 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 eureka.instance.* is driven by the configuration key, but if you ensure that your application has spring.application.name (this is the default value for the Eureka Service ID or VIP), the default value will be normal.

Source Source

Follow me to learn spring Cloud Netflix client use

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.