What is a Service registry
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 fundamental infrastructures in an SOA architecture.
1 The role of the service registry
- Registration of services
- Discovery of services
2 What are common registries
- Dubbo’s registry, Zookeeper
- Eureka, Springcloud’s registry
What problems does the service registry solve
- Service management
- Dependency management of services
4 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 subproject spring-Cloud-Netflix to register Spring Cloud services for discovery, and also provides load balancing, failover, and other capabilities.
5 Three roles in Eureka registry
5.1 Eureka Server
Registers and discovers services through interfaces such as Register, Get, and Renew.
5.2 Application Service (Service Provider)
Service providers register their service instances with Eureka Server
5.3 Application Client (Service Consumer)
The service caller obtains the list of services from Eureka Server and consumes the services
2. Introduction to Eureka
1. Create a SpringBoot project
Create a SpringBoot project
2. Introduce related dependencies
Add the following dependencies
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-config</artifactId> < version > 1.4.5. RELEASE < / version > < / dependency > < the dependency > < groupId > org. Springframework. Cloud < / groupId > < artifactId > spring -- cloud - starter - eureka - server < / artifactId > < version > 1.3.2. RELEASE < / version > < / dependency > </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Dalston.SR5</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>Copy the code
Creating an Initiator
In the startup class we need to let go of @enableEurekaserver to indicate that this is a server for Eureka
@EnableEurekaServer @SpringBootApplication public class SpringcloudEurekaDemoApplication { public static void main(String[] args) { SpringApplication.run(SpringcloudEurekaDemoApplication.class, args); }}Copy the code
Modify the application.properties file
Name =eureka-server server.port=8761 The default is true eureka.client.register-with-eureka=falseCopy the code
Start the service to access the Web page
If the service can be accessed after it is started, it is successfully started
The Server is started successfully. Next Chapter HA on the Server