I. Overview
Our microservices can be broadly divided into the following two categories:
[1] Producers of services
[2] Consumers of the service
Service between the producer and the consumer through the service center to determine the other party's existence, and the other's basic information.
The following describes the relationship between the three:
[1] When the producer starts, it registers its own information (description of the hostname+port+ micro-service) on the service center.
[2] The consumer discovers the producer's information through the service center and then invokes the producer's microservices as appropriate.
Let's take a look at the following view:
We can see the basic relationship between the three, and all microservices need to register themselves on the Service Discovery Component (Service center).
The microservices call is then completed by registering the information on the service center.
Here are a few concepts to be covered:
[1] Each micro-service needs to have a applicationname, the name of the application describes what services they provide
[2] Each registration information must contain its own hostname and port information, or the micro-service can not be invoked.
[3] Each registered microservices need to have a instanceid (also can be said to be the name of the instance), usually each instance of the name is not the same, we can use the name of the instance to quickly know what the micro-service is doing.
Two. Role of service centres
The role of the service center is mainly concentrated in the following two areas:
[1] Registration of services: every micro-service needs to register its own information to the service center, so that other micro-services can know the existence of the micro-service.
[2] Service discovery: Refers to the ability to find a microservices instance through a service center (mainly hostname and port).
In Springcloud, our most used service center is Eureka. Below we will build a service center of our own.
002 Service Center