Eureka is one of Springcloud Netflix's sub-modules for cloud-service discovery, service positioning, and cloud-tier service discovery and failover. Service registration and discovery is very important for the microservices system, and with the service registration and discovery, it saves the hassle of changing the configuration file of service invocation every day. You only need to use the service identifier, or you can use the service. It functions like a registry with Dubbo.
Service discovery: Service discovery is one of the key principles of microservices infrastructure, and Eureka is a service and client that Netflix service discovers. This service can be configured and deployed with high availability, and the status of each service can be replicated to each other within the registered service.
Service registration: When a client registers to Eureka, it provides metadata about itself (such as host and port, health metrics URL, home page, etc.) Eureka receives heartbeat information from each instance through a service. If the heartbeat fails to receive more than the configured time, the instance will normally be removed from the registration.
is the basic service registration and discovery:
Eureka Service Discovery and Registration (create a Registry) 1: Create a basic spring boot project and introduce the required dependencies in the Pom.xml
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.ysl</groupId> <artifactid>serviceregister</artifactid > <version>1.0-snapshot</version> <packaging>jar</packaging> <name>eureka_register_service</name > <description>spring Cloud service register</description> <parent> <groupid>org.s Pringframework.boot</groupid> <artifactId>spring-boot-starter-parent</artifactId> <vers Ion>1.4.3. release</version> </parent> <properties> <project.build.sourceencoding>utf-8</project.build.sourceEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupid>o Rg.springframework.boot</groupid> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupid>org.sprin Gframework.cloud</groupid> <artifactId>spring-cloud-starter-eureka-server</artifactId> </dependency> </dependencies> <dependencyManagement> <dependencies> <d Ependency> <groupId>org.springframework.cloud</groupId> <ARTIFACTID>SPR Ing-cloud-dependencies</artifactid> <version>Brixton.RELEASE</version> < ;type>pom</type> <scope>import</scope> </dependency> </depe Ndencies> </DEPendencymanagement> <build> <plugins> <plugin> <groupid>org. Springframework.boot</groupid> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build></project>
2: Create a Startup class application
Package Com.ysl;import Org.springframework.boot.springapplication;import Org.springframework.boot.autoconfigure.springbootapplication;import Org.springframework.cloud.netflix.eureka.server.EnableEurekaServer, @EnableEurekaServer @springbootapplication Public class application { publicstaticvoid Main (string[] args) { springapplication.run (application. class , args);} }
Start a service registry with @enableeurekaserver annotations to provide conversations to other apps.
3: Create a profile application.properties, be careful not to appear blank, no start error
server.port=8000eureka.client.register-with-eureka=falseEureka.client.fetch -registry=falseeureka.client.service-url.defaultzone=http://localhost:${ server.port}/eureka/
4: Start the service, view the registration center
Http://127.0.0.1:8000/can be seen as:
Why even login account and password are not, outside the network is not directly able to enter the registration center, so it is not safe ah. Okay, then we'll add the login ID and password.
Eureka Registration Center Join permissions
1: Join the registry need to introduce Jar, join in Pom.xml
<dependency> <groupId>org.springframework.boot</groupId> <artifactId> Spring-boot-starter-security</artifactid></dependency>
2: Configuration file Create a new bootstrap.yml file
Security: basic: true User: name:admin password:admin
Since then, the registry has been created to complete
Springcloud Service registration and service Discovery Eureka