Micro-Service Architecture Springcloud (ii) Eureka (service registration and service Discovery Basics)

Source: Internet
Author: User

A: Eureka Introduction

Eureka is a sub-module of spring Cloud Netflix and one of the core modules. For cloud service discovery, a rest-based service for locating services to enable mid-tier service discovery and failover in the cloud.

Service registration and discovery is very important for microservices systems. With the service discovery and registration, you do not need to change the service call configuration file all day, you just need to use the service identifier, you can access to the service. His function is similar to Dubbo's registry.

Service discovery: Service discovery is one of the key principles of microservices infrastructure. Attempting to configure a contract for each client or a format can be said to be very difficult and very fragile. Eureka is a service and client discovered by the Netflix service. 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

II: Eureka Service Discovery and Registration (create Registry)

1:创建一个基础的Spring Boot工程,并在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. Demo.springcloud</groupid> <artifactId>eureka_register_service</artifactId> <version&gt ;1.0.0</version> <packaging>jar</packaging> &LT;NAME&GT;EUREKA_REGISTER_SERVICE&LT;/NAME&G        T <description>spring Cloud project</description> <parent> <groupid>org.springfram Ework.boot</groupid> <artifactId>spring-boot-starter-parent</artifactId> <versi            on>1.4.3.release</version> <relativepath/> </parent> <properties> <project.build.sourceeNcoding>utf-8</project.build.sourceencoding> <java.version>1.8</java.version> </ properties> <dependencies> <dependency> <groupid>org.springframework .boot</groupid> <artifactId>spring-boot-starter-test</artifactId> <scop e>test</scope> </dependency> <dependency> &LT;GROUPID&GT;ORG.SPR            Ingframework.cloud</groupid> <artifactId>spring-cloud-starter-eureka-server</artifactId> </dependency> <dependency> <groupid>org.springframework.boot</gr        Oupid> <artifactId>spring-boot-starter-security</artifactId> </dependency> </dependencies> <dependencyManagement> <dependencies> <depend                Ency>    <groupId>org.springframework.cloud</groupId> <artifactid>spring-cloud-dependencie S</artifactid> <version>Brixton.RELEASE</version> <type>pom& lt;/type> <scope>import</scope> </dependency> </depen dencies> </dependencyManagement> <build> <plugins> <plugin > <groupId>org.springframework.boot</groupId> <artifactid>sprin    g-boot-maven-plugin</artifactid> </plugin> </plugins> </build>     </project>

2: Create a Startup class application

package com.demo.springcloud; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; @EnableEurekaServer @SpringBootApplication public class Application {   public static void 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=8000 eureka.client.register-with-eureka=false eureka.client.fetch-registry=false eureka.client.serviceUrl.defaultZone=http://localhost:${server.port}/eureka/

4: Execute the bluid.sh to build and then execute the main method. I have not been manually compiled under Eclipse, the boot time has been not read application.properties.

The schema code is as follows:

MicroServices Architecture Springcloud (ii) Eureka (service registration and Service Discovery Basics)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.