Eureka Quick Start
remote call problem
Multiple services have multiple ports, so there are multiple services, hard coding is not suitable
The role of eureKa
- Record all the service ports of the service. If you want, query directly from the registration center.
- For all services, you need to send a request to eureKa every once in a while to ensure that the service is still alive
Hands
Build eureKa registration center
Three steps:
- Introduce server-side dependencies
- add annotation
- configuration
register user-service
Register the service service to the eureka service, the same as the order service
- two steps
- Introduce dependencies
- Add client configuration and remember to pay attention to the name of the service
in conclusion:
- Introduce eureka-client dependency
- Configure eureka address in applicatin.yml
Complete service pull in order-service
Service pull is to obtain the service list based on the service name, and then perform load balancing on the service list
- Introduce eureka-client dependency
- Configure the eureka address in application.yml
- Add the @LoadBalanced annotation to restTemplate because there are multiple services adding this annotation can dynamically select services to achieve load balancing
- Remote call with the service name of the service provider