This article was adapted from: Lebyte
Eureka Registry for Java Microservices
Service registry is the core component of service management. Similar to directory service, it is mainly used to store service information, such as provider URL string and routing information. A service registry is one of the most basic infrastructures in a microservices architecture.
Registries began to appear in distributed architectures long before microservice architectures became popular. For example, Dubbo is a popular distributed framework in China, which is adopted by a large number of small and medium-sized Internet companies. It provides relatively perfect service governance functions, and the realization of service governance mainly depends on the registry.
What is a registry
A registry is the “address book” of the microservices architecture, recording the mapping between services and service addresses. In a distributed architecture, services are registered here, and when a service needs to call another service, it finds the address of the service and makes the call.
To take a real life example, for example, there are two usage scenarios of the address book in our mobile phone:
When I want to call Zhang SAN, I need to find him by name in the address book, and then I can find his mobile phone number to make a call. — The service found that Li Si had a mobile phone number and told me the number. I saved Li Si’s number in the address book, and then I could find him from the address book. Service registration address book? What role (Hint: Service registry)
Summary: The purpose of a service registry is to register and discover services.
A common registry
- Netflix Eureka
- Alibaba Nacos
- HashiCorp Consul
- Apache ZooKeeper
- CoreOS Etcd
- CNCF CoreDNS
features | Eureka | Nacos | Consul | Zookeeper |
---|---|---|---|---|
Why do you need a registry
Now that we know what a registry is, let’s move on to why we need one. In distributed systems, there are more complex issues to consider than simply finding a mapping between a service and its address in a registry:
- How can services be discovered after registration
- How can I log out of a service in a timely manner
- How can services scale horizontally effectively
- How to route a service when it is discovered
- How can I degrade a service when it is abnormal
- How can registries make themselves highly available
The resolution of these problems depends on the registry. Registry functions like a DNS server or a load balancer, but in reality, as a basic component of microservices, registries can be more complex and require more flexibility and timeliness. Therefore, we still need to learn more Spring Cloud microservice components to cooperate with application development.
What problems does the registry solve
- Service management
- Dependency management of services
What is the Eureka Registry
Eureka, a Service discovery component developed by Netflix, is itself a REST-based service. Spring Cloud integrates it into its sub-project, Spring Cloud Netflix, to realize service registration and discovery of Spring Cloud, and also provides load balancing, failover and other capabilities.
Eureka registry has three roles
Eureka Server
Registers and discovers services through interfaces such as Register, Get, and Renew.
Application Service (Service Provider)
The service provider registers its service instance with Eureka Server.
Application Client (Service Consumer)
The service caller gets the list of services through Eureka Server and consumes the services.
Java micro service Eureka registry entry case I put in the public number “Lebyte” inside, the public number needed to send a message: 999