spring cloud(3) eureka client

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

----- equal zk messaging provider inside producers.

1. Prepare

https://github.com/ITfqyd/springcloud

Down loading this download, the idea put into, can be used to update the maven

Remember: because my project is Project Cohesion, therefore, jar, following blog parent module is not increased.

2.eureka client settings

    2.1 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.fqyd</groupId>
    <artifactId>springcloud-eureka-client</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>springcloud-eureka-client</name>
    <packaging>jar</packaging>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>com.fqyd</groupId>
        <artifactId>springcloud</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

    <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.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</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>
</project>
注意:
1. client使用的是spring-cloud-starter-netflix-eureka-client
2.版本问题,spring boot2.0以上的版本使用的是Finchley开头的。
3.2.0以下和2.0的依赖多来netflix,2.0以下引入的是spring-cloud-starter-eureka-client

2.2 application.yml

server:
  port: 8762
spring:
  application:
    name: eurka-client
eureka:
  instance:
    hostname: localhost
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/

note:

1. port problems, previous port is 8761, this was changed to 8762 to ensure that the port does not conflict, or they reported problems running the port occupied by (a lot of information online are written by the same).

Name 2.spring application name changed to different

3. Set before the eureka there, get rid of, otherwise, does not register itself

 

register-with-eureka  由于该应用是注册中心,false:代表不向注册中心注册自己;true:代表注册自己
fetch-registry 是否启动检测服务

4. HTTP: // localhost: 8761 / Eureka /   where localhost and 8761 are not the way to write, but to configure localhost and 8761 Le registry Eureka server in springcloud (II). Do not understand, please see the corresponding blog

https://blog.csdn.net/qq_16855077/article/details/90752257

2.3 startup class

package com.fqyd.springcloudeurekaclient;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;


@EnableDiscoveryClient   //更通用,支持服务发现组件
//@EnableEurekaClient    专属的组件
@SpringBootApplication
public class SpringcloudEurekaClientApplication {

    public static void main(String[] args) {
        System.out.println("启动————提供服务者");
        SpringApplication.run(SpringcloudEurekaClientApplication.class, args);
    }

}

Note: These two notes can be used, but more widely used, because he could not support eureka service can also be found as zk class service.

3. operating results

http://localhost:8761/

 We can see by the screenshot has been registered service came.

DESKTOP-8S3CENH:eurka-client:8762 

Split the instructions under

DESKTOP-8S3CENH  is the computer name (ip herein may be provided as a display, needs to be configured, it will be described in detail later)

eurka-client:  is the name of the spring

8762: is a registered service port

Note: Sometimes the server does not come in registration may occur.

For example: my local network adapter configuration

Pictures, I've got a virtual machine, Ethernet, wireless, vpn, ip acquired in the code, do not know why Ethernet is the highest priority. Specific reasons not clear, clear friends can leave a comment below.

Test scenarios: in the code to write code to obtain ip, vpn address is obtained each time, after I put the rest are disabled, leaving only Ethernet, ip access was normal.

Found that the above services are registered as a DESKTOP-8S3CENH: eurka-client: 8762   this is not conducive to let us know that this service is registered from which over ip, management is not convenient, so here need to set up, change the computer name to ip

 

 

ok. The host name into ip completed, you're done!

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

Guess you like

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