First, how to solve the hard coding problem
Last lesson we learned about the service provider and service providers, one of the very big problem is hard coding problem, it is well known that in the Internet development, the IP and port number of access address is dynamic, a service is stopped and re-enabled after the IP and port may have changed, so hard coding is definitely not. So we tried to use the new technology to solve the problem.
Second, service discovery
Based on the above mentioned problem, the solution is to use the service discovery component to dynamically maintain access paths and other relationships, as shown in the following figure. The service provider registers the IP and port with the service discovery component, and when a service consumer needs a consumer service, it simply needs to go to the service Discovery component to get access to the path. So how are their relationships maintained? In fact, it is also used in the heartbeat mechanism, that is, service providers and service consumers in the service Discovery component after registration every fixed time will send a heartbeat, the service found that the component received the heartbeat will be considered to be managed objects are available, if the heartbeat is not received for a long time, The service discovery component then considers that the object has been hung out and then deletes its registration information. The IP and port of the suspended service provider are no longer used when the service is available.
Third, the function of service discovery component
The capabilities of the service discovery component are divided into three:
1. Service Registration Form
The service registry is a database that records the network information of the currently available service instances and is at the heart of the service discovery mechanism. The Service registry provides query APIs and management APIs, uses the query API to obtain available service instances, and uses the management API to implement registration and logoff.
2. Service Registration
The registration function is the premise, the service component wants to provide the service externally, at least must have for it to manage the service only then, therefore the registration function is the foundation, is the premise.
3. Health Check
After a service is registered with a service component, the service Discovery component also checks to see if the services that are registered are already down, and if it goes down, no longer provides the services provided by the service.
Iv. Ways of Service discovery
1. Client Discovery
Client-side discovery is common in two ways, namely Eureka and zookeeper
The common way to find the server is Consul+nginx
So, what are the similarities and differences between client discovery and server discovery, you can refer to: http://blog.daocloud.io/microservices-4/this article to learn. Currently, Eureka is the most suitable technology for service discovery.