007 SpringCloud study notes 3 ----- Eureka registry

1. Eureka Overview

(1) primer

Appear before the network about cars, people can call a taxi cab to go out. Some wanted to hire a private car did not qualify, known as the black car. And many people want about the car, but the taxi helpless little inconvenient. Many private cars but did not dare stopped, and filled the car, who knows which one is willing manned. A want, a willingness to give, is the lack of management ah.
At this point drops this network platform about cars appeared, all want to carry passengers to all private cars registered by bit, record your car (type of service), identity information (contact). This provides private car service, and pieces can be found in there, at a glance.
At this point people want to hire a car, just open the APP, enter your destination, select models (Type of Service), automatically schedule a bit to meet the needs of the car in front of you, for your service, perfect!

Eureka is like drops, responsible for the management, records information service provider . Service the caller without having to find their own services, but to their own needs to tell Eureka, and Eureka will meet your service needs to tell the service the caller.
At the same time, the service provider between the parties and monitored by `Eureka" heartbeat "` mechanism, when a service provider problem, Eureka will naturally reject it from the service list. This enables automatic registration services, discovery, status monitoring.
(2) Schematic

- Eureka: is the service registry (can be a cluster) external to reveal their address
- Provider: After starting their own registration information (address, what services are provided) to Eureka
- Consumers: subscription services to Eureka, Eureka will correspond All service providers address list is sent to the consumer, and is updated regularly
- heartbeat (renewal): provider regularly refresh their status through http way to Eureka

2. Getting Case

We create a project, start a EurekaServer

(1) Spring Scaffolding (Spring Initializr) Create Project

 

Automatically generated pom file

<?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>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.1.RELEASE</version>

        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>lucky.eureka</groupId>
    <artifactId>lucky-eureka</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>lucky-eureka</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>Greenwich.SR2</spring-cloud.version>
    </properties>

    <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>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

(2) The code portion

<1> write application.yml configuration:

Server: 
  Port: 10086 # port of 
the Spring: 
  the Application: 
    name: Eureka-Server # application name will be displayed in Eureka in 
Eureka: 
  Client: 
    Service-url: # EurekaServer address, now is their address, if the cluster, and needs the addresses of other Server. 
      defaultZone: http: // localhost: $ {server.port} / eureka

<2> class guided modify, add annotations on @EnableEurekaServer categories:

package lucky.eureka;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@SpringBootApplication
@EnableEurekaServer    //启用eureka服务端
public class LuckyEurekaApplication {

    public static void main(String[] args) {
        SpringApplication.run(LuckyEurekaApplication.class, args);
    }

}

(3) Effects of FIG.

 

Guess you like

Origin www.cnblogs.com/luckyplj/p/11449142.html