Home > Java > javaTutorial > body text

What does Spring Cloud Netflix Eureka do?

王林
Release: 2024-04-18 08:33:02
Original
903 people have browsed it

Eureka is a framework for service discovery and registration in Spring Cloud Netflix. Its specific functions include: allowing services to register with Eureka through the REST API; allowing clients to discover registered services through Eureka; Eureka will regularly send heartbeats to registered services , and delete unhealthy or unresponsive services from the registry; Eureka provides the client with a service list and can perform balanced distribution according to the configured load balancing policy.

Spring Cloud Netflix Eureka 的作用是什么?

Spring Cloud Netflix Eureka: Service Discovery and Registration

Introduction

Spring Cloud Netflix Eureka is a service discovery and registration framework in a microservice architecture. It is based on Netflix's Eureka service and provides dynamic service discovery, load balancing and fault tolerance.

Function

The main functions of Eureka are as follows:

  • Service registration: Allows services to register with Eureka through REST API Register themselves.
  • Service Discovery: Allows clients to discover registered services through Eureka.
  • Health check: Eureka will periodically send heartbeats to registered services and delete unhealthy or unresponsive services from the registry.
  • Load balancing: Eureka provides a service list for clients and can perform balanced distribution according to the configured load balancing policy.

Practical case

1. Service registration

In Spring Boot application, you can use@EnableEurekaClient Annotation to enable Eureka service registration:

@SpringBootApplication
@EnableEurekaClient
public class MyApplication {
    // ...
}
Copy after login

2. Service discovery

Eureka will run on port 8761 by default. Client applications can use the @LoadBalanced annotation to apply load balancing policies to the injected RestTemplate:

@RestController
public class MyController {
    @Autowired
    @LoadBalanced
    private RestTemplate restTemplate;
    
    @GetMapping("/")
    public String index() {
        String result = restTemplate.getForObject("http://my-service/", String.class);
        // ...
        return result;
    }
}
Copy after login

3. Health Check

Eureka Pre- The device will send a heartbeat to the registration service every 30 seconds. You can customize the health check path by setting the property eureka.instance.healthCheckUrlPath in application.properties:

eureka.instance.healthCheckUrlPath=/health
Copy after login

Conclusion

Spring Cloud Netflix Eureka is a powerful and easy-to-use framework for service discovery and registration. It provides dynamic service discovery, load balancing, and fault tolerance capabilities, thereby simplifying the development and maintenance of microservice architectures.

The above is the detailed content of What does Spring Cloud Netflix Eureka do?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template