Services are the core of the micro-service architecture, which is mainly used to automate the registration and discovery of individual microservices instances.
1. Service Registration
In the service governance framework, a registry is typically built, and each service unit registers its own services with the registry, hosting, ports, version numbers, communication protocols, etc.
Additional information informs the Service center that the registry organizes the list of services by service name.
2. Service Discovery
Because of its operation under the Service governance framework, calls between services are not implemented by specifying a specific address instance address, but rather by initiating a request invocation by a service name.
Use spring Cloud Eureka to build a service registration center
<1>. First we create a foundation project through Spring Initializer, named Eureka-server
<2>. Add the following dependencies in the POM
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId> Spring-cloud-starter-eureka-server</artifactid>
</dependency>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Brixton.SR5</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<3>. Add annotations @EnableEurekaServer start the registration center
@EnableEurekaServer // Open Service registration service @SpringBootApplicationPublicclass eurekaserverapplication { publicstaticvoid main (string[] args { new springapplicationbuilder (eurekaserverapplication). Class). Web (true). Run (args); }}
<4>. Add the following configuration in the Application.properties
server.port= 1111eureka.instance.hostname= localhost# does not need to register itself with the registry Eureka.client.register- With-eureka=false# does not need to retrieve service Eureka.client.fetch-registry=false Eureka.client.serviceUrl.defaultZone= http://${eureka.instance.hostname}:${server.port}/ Eureka
<5>. Start the service and access http://localhost:1111/to see the following Service registration page
Spring Cloud Eureka Service governance