Photo credit: One Minute at Hengshui Middle Schoolwww.bilibili.com/video/BV14E…
Why have a registry
In the front-end and back-end separation architecture, the service layer is divided into many microservices. How is the information of microservices managed? A service registry is provided in Spring Cloud to manage microservice information. Why use a registry?
- The registry helps us manage the IP address and port of the service side in order to make remote calls.
- Microservices report their status in real time, and the registry manages the status of these microservices in a unified manner. Problematic services are removed from the service list, and the client obtains available services for invocation.
Had been introduced
SpringCloudEureka is the secondary encapsulation of Eureka of Netflix, which realizes the function of service governance. SpringCloudEureka provides both server and client, and the server is the Eureka service registry. The client completes the registration and discovery of the micro-service to Eureka service. Both the server and client are written in Java language.
Set up the environment
Add the dependent
Parent project dependency
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.SR1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Copy the code
Eureka Server project
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
</dependencies>
Copy the code
Start the class @ EnableEurekaServer
@EnableEurekaServer // Mark this as a EurekaServer
@SpringBootApplication
public class GorvernCenterApplication {
public static void main(String[] args) { SpringApplication.run(GorvernCenterApplication.class,args); }}Copy the code