Spring Cloud Learning Notes-003
- Service provider: Registering the service with the registration center
1. New Maven project, skeleton selection QuickStart, project name: Demo-member
2. Join related dependencies:
3. Write the Service interface:
4. Create a new Application.yml file in the Src\main\resources directory:
5. Write the Startup class:
6. Start the project and visit the Eureka homepage to view the results (note: To start the Eureka Registry first):
7. Sometimes you will see this red warning message when you start Eureka:
This warning is triggering the Eureka server's self-protection mechanism . When the service is registered with Eureka Server, a heartbeat connection is maintained, telling Eureka that the server is alive. Eureka server During the run, will be counted whether the rate of heartbeat failure is less than 85% in 15 minutes, if there is less than the situation (when the single-machine debugging is easy to meet, the actual production environment is usually caused by network instability), Eureka The server protects the current instance registration information so that the instances do not expire and protects the registration information as much as possible. However, if there is a problem in this protection device instance, then the client (service provider or service consumer) can easily get the service instance that does not exist, so the client must have fault-tolerant mechanism such as request retry, circuit breaker and so on.
Because local debugging can easily trigger a registry protection mechanism, this makes the service instances maintained by the registry less accurate. Therefore, when we are developing locally, we can use the Eureka.server.enalbe-self-preservation=false parameter to turn off the protection mechanism to ensure that the registry can remove the unavailable instances correctly.
Spring Cloud Learning Notes-003