springcloud (b) the registry Eureka server

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/qq_16855077/article/details/90752257

1. Description

 Service Center, also known as the registry, management of various service functions including service registration, discovery, fuse, load, demotion, etc., such as a variety of functions dubbo admin background.

A normal call request Project B Project

Once you have the service center, any service can not be directly removed with, we need to call through the service center

 This is only the most complex scenes, if dozens, hundreds service, under imagine, and sometimes change an address, a number of projects involved, and this time, the registration service comes in handy Le.

 

1, the service discovery component

  • Provide service registry and found similar with zk.

2, the service provider

  • The service provider will register their services to Eureka, so that the service consumer to find

3, the service consumer

  • Obtain a list of registered services from Eureka, thereby Consumer Services

2 server to achieve

    2.1pom.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>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.cloudtech</groupId>
    <artifactId>eureka</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>eureka</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
    </dependencies>

    <!-- Spring Cloud 管理依赖 -->
    <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>

    <repositories>
        <repository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

</project>

 2.2 application.yml

server:
  port: 8761
spring:
  application:
    name: eurka-server
eureka:
  instance:
    hostname: localhost
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
  • eureka.client.register-with-eureka : Indicates whether to register itself to Eureka Server, the default is true.
  • eureka.client.fetch-registry : Indicates whether to obtain registration information from Eureka Server, the default is true.
  • eureka.client.serviceUrl.defaultZone : Set interaction with Eureka Server address, tracking and registration services will need to rely on this address. The default is http: // localhost: 8761 / eureka; a plurality of addresses may be used, separated.

2.3  EurekaApplication.java

package com.cloudtech.eureka;

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

@EnableEurekaServer
@SpringBootApplication
public class EurekaApplication {

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

}
@EnableEurekaServer 可能会报红色字体,可能是因为idea没有帮我们自动导入报的问题,alt+enter一下,选择import class。

Start the project, you may encounter the following error

There may be other errors, probably got me maven jar package fails, it is recommended to delete all the jar packages maven local library, download it again, I pulled twice, it does not run error.

3. Run 

Direct input localhost: 8761

4.eureka interface explain

View recent 1000 service

There are several current eureka cluster node

 Other micro-services will appear here. Because I only started the service registry, so there is no display

system status 

When the service starts

General information

From top to bottom, memory size, environment, cpu audit, etc. 

Examples of information

What ipAddr indicates that the eureka server address is

status: UP, up indicates normal 

5 code address

Before considering the idea because not only put a window of a project, multiple projects need to switch back and forth window, so that development efficiency is very low, so I took the time to transform the project into an aggregate project. To achieve the above FIG effect

1. Update parent and child of two pom maven

2. Run sub-module directly springcloud-eureka-server

https://github.com/ITfqyd/springcloud

如果你热衷技术,喜欢交流,欢迎加入我们! 

 

Guess you like

Origin blog.csdn.net/qq_16855077/article/details/90752257