Introduction to Spring Cloud's Eureka

Source: Internet
Author: User

Recently there are some problems with the interface, some may not be the problem of the code, but because the test and other colleagues burst out, so the sense of monitoring the interface should be put on the agenda.

Search has found that spring Cloud's Eureka is dedicated to doing this work.

The following paragraph is a brief introduction to Eureka in the book "Spring Cloud Micro Service":

Spring Cloud Eureka is part of the spring cloud Netflix MicroServices Suite, which has two footprints based on Netflix Eureka and is primarily responsible for service governance capabilities in the MicroServices architecture.

By adding spring boot-style automation to Eureka, Spring Cloud simply integrates the MicroServices applications built by spring boot with a simple introduction of dependency and annotation configurations to easily integrate with the Eureka Service governance system.

Three roles of Eureka services:

? Service Registration Center:

Eureka provides the service side, provides the service registration and the discovery function, generally is called eureka-server.
? Service provider:

Applications that provide services can be spring Boot applications or other technology platforms that follow the Eureka communication mechanism. It registers its own services with Eureka for other applications to discover
? Service Consumers:

The consumer app gets a list of services from the service registry, so that consumers can know where to call the services they need, which is not part of our content and is not covered.

Second, the simple construction of server in Eureka

1. First we create an application called Monitor, which first introduces the Eureka dependency

< Dependency > < groupId >org.springframework.cloud</groupId><Artifactid  >spring-cloud-starter-eureka-server</artifactid> </ Dependency >

2. Because it is a spring cloud project, it also requires spring Cloud's dependency management

<dependencymanagement>        <Dependencies>            <Dependency>                <groupId>Org.springframework.cloud</groupId>                <Artifactid>Spring-cloud-dependencies</Artifactid>                <version>Dalston.sr1</version>                <type>Pom</type>                <Scope>Import</Scope>            </Dependency>        </Dependencies></dependencymanagement>

Note: Spring boot and Spring cloud have strict version correspondence, the spring boot version of this project is 1.5.4.RELEASE

3.application.properties configuration file

Spring.application.name=eureka-serverserver.port=8080eureka.instance.hostname= Localhosteureka.client.register-with-eureka=falseeureka.client.fetch-registry=false

4. Last step, apply the entry class to add annotations

@EnableEurekaServer

So this project is a Eureka Service registration center.

Third, Eureka's client simple construction

Eureka clients are usually our application, we need to monitor them.

1.application.properties configuration file

Spring.application.name=client-nameserver.port=8080# Important: Register your app with the service registry in the previous step Eureka.client.serviceUrl.defaultZone=http://*.*.*.*:8080/monitor-1/eureka /#开启端点management. security.enabled=false#监测心跳eureka. Instance.health- Check-url-path=/health

Dependency of 2.pom files

<Dependency>    <groupId>Org.springframework.cloud</groupId>    <Artifactid>Spring-cloud-starter-eureka</Artifactid></Dependency><Dependency>    <groupId>Org.springframework.boot</groupId>    <Artifactid>Spring-boot-starter-actuator</Artifactid></Dependency>

3.spring Cloud's dependency management

<dependencymanagement>        <Dependencies>            <Dependency>                <groupId>Org.springframework.cloud</groupId>                <Artifactid>Spring-cloud-dependencies</Artifactid>                <version>Dalston.sr1</version>                <type>Pom</type>                <Scope>Import</Scope>            </Dependency>        </Dependencies></dependencymanagement>

4. Add annotations using the entry class

@EnableDiscoveryClient

5. Last step, introduce the Discoveryclient object in the controller

@Autowired Private Discoveryclient client;
Iv. Monitoring UI

See this, the basic is done.

Introduction to Spring Cloud's Eureka

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.