Spring Cloud Eureka

Source: Internet
Author: User

One. NetFlix Eureka

Spring Cloud Eureka implements service registration in discovery through NETFLIEX Eureka, which contains server-side components that also contain client components.

Eureka Service Side

Service registration: in the service governance framework, a registry is typically built, and each service unit registers its own services with the registry and informs the Registry of additional information such as the host and port number, version number, communication protocol, and so on.

    The registry organizes the list of services by service name.

        

Service discovery: because calls between services that operate within a service governance framework are no longer implemented by specifying a specific instance address, they are implemented by initiating a request to the service name. So the service caller is invoking the service provider interface

The location of the specific service instance is not known, so you need to ask for a registration center to get an example list of all the services.

Second, create the Service registration center

Here we need to use the components on spring Cloud Netflix Eureka, Eureka is a service registration and Discovery module.

Pom.xml file

<?XML version= "1.0" encoding= "UTF-8"?><Projectxmlns= "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.forezp</groupId>    <Artifactid>Eurekaserver</Artifactid>    <version>0.0.1-snapshot</version>    <Packaging>Jar</Packaging>    <name>Eurekaserver</name>    <Description>Demo Project for Spring Boot</Description>    <Parent>        <groupId>Org.springframework.boot</groupId>        <Artifactid>Spring-boot-starter-parent</Artifactid>        <version>1.5.2.RELEASE</version>        <RelativePath/> <!--Lookup parent from repository -    </Parent>    <Properties>        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>        <java.version>1.8</java.version>    </Properties>    <Dependencies>        <!--Eureka Server -        <Dependency>            <groupId>Org.springframework.cloud</groupId>            <Artifactid>Spring-cloud-starter-eureka-server</Artifactid>        </Dependency>        <!--Spring Boot Test -        <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>Dalston.rc1</version>                <type>Pom</type>                <Scope>Import</Scope>            </Dependency>        </Dependencies>    </dependencymanagement>    <Build>        <Plugins>            <plugin>                <groupId>Org.springframework.boot</groupId>                <Artifactid>Spring-boot-maven-plugin</Artifactid>            </plugin>        </Plugins>    </Build>    <repositories>        <Repository>            <ID>Spring-milestones</ID>            <name>Spring Milestones</name>            <URL>Https://repo.spring.io/milestone</URL>            <Snapshots>                <enabled>False</enabled>            </Snapshots>        </Repository>    </repositories>

2.1 Start a service registry, you need only one annotation @enableeurekaserver, this annotation needs to be added to the Springboot project's Startup application class:

@EnableEurekaServer @springbootapplication  Public class eurekaserverapplication {    publicstaticvoid  main (string[] args) {        Springapplication.run (eurekaserverapplication. class , args);}    }

Eureka is a highly available component that does not have a back-end cache, each instance is registered to send a heartbeat to the registry (so it can be done in memory), and by default Erureka server is also a Eureka client, and you must specify a server. Eureka Server configuration file Appication.yml:

Server:  Port:8761eureka:  instance:    hostname:localhost  client:    registerwitheureka:false    fetchregistry:false    serviceurl:      defaultzone:http://${eureka.instance.hostname}:${server.port}/ eureka/

Spring Cloud 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.