1. Briefly, what is eureka
Eureka is a Netflix open source product that provides service registration and discovery. It provides a complete implementation of Service Registry and Service Discovery. It is also one of the most important and core components in the spring cloud system.
I simply understand it as the registration center. All services must be registered in the registry, and all call paths are obtained in the registry
2. Start eureka
(1) Project initialization
Establish a eureka project from scratch, and you can directly access the official initialization platform of spring https://start.spring.io/ , it can also be generated by using the spring initializr plug-in on idea, and the steps are the same.
After writing the name of your project and selecting the spring boot and Java version, select the add dependencies required by the project. You can directly search eureka in the plug-in. You can select it directly in the category and check it to confirm.
The following is the operation steps on idea: right click on the project = "new =" module = "Spring initializr", and then next. The following interface appears to modify the pointed contents
Then select the dependency next (as shown in the figure below). The last way is next finish.
(2) Project overview
After the above operations, you can get an item after initialization
Important pom files are as follows (if there is an initialized spring boot project, it is also possible to directly add relevant pom dependencies)
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>groupId</groupId> <artifactId>spring-cloud-demo</artifactId> <version>1.0-SNAPSHOT</version> </parent> <groupId>com.demo</groupId> <artifactId>eureka</artifactId> <version>0.0.1</version> <name>eureka</name> <description>Registration Center</description> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> </project>
Other documents will be modified later. See below.
(3) Modify yml configuration file
The YML file (application.yml, renamed from application.properties) is as follows
eureka: server: enable-self-preservation: false #Turn off self-protection mechanism eviction-interval-timer-in-ms: 4000 #Set the cleaning interval (unit: ms, default: 60 * 1000) instance: hostname: eureka client: registerWithEureka: false #Don't register yourself as a client fetchRegistry: false #You don't need to get the registration information from the server (because you are the server here, and your registration has been disabled) serviceUrl: defaultZone: http://Localhost: the address of ${server. Port} / Eureka / #eureka server. The deployment address is written for a single machine
(4) Add startup class annotation
Add the annotation @ EnableEurekaServer (org.springframework.cloud.netflix.eureka.server.EnableEurekaServer) on the startup class
The basic configuration of such a stand-alone registration center is good
(5) Start effect
Access after local startup http://localhost:3000 The effect is as follows
Such a registration center is completed;
(6) Supplement (service provider and service consumer)
Here, a stand-alone registration center has been built, but it is not sure whether the functions of this registration center are available; Therefore, if you need to verify whether the function is complete, you also need to have service providers and service consumers jointly test the registration and discovery function of the registry.