• Spring Cloud(2)A Eureka server端 服务注册建立


    1. 父项目pom

     1    <dependency>
     2       <groupId>org.springframework.cloud</groupId>
     3       <artifactId>spring-cloud-dependencies</artifactId>
     4       <version>Greenwich.RELEASE</version>
     5       <type>pom</type>
     6     </dependency>

    10 <dependency> 11 <groupId>org.springframework.boot</groupId> 12 <artifactId>spring-boot-dependencies</artifactId> 13 <version>2.1.3.RELEASE</version> 14 <type>pom</type> 15 <scope>provided</scope> 16 </dependency>

    2.Eureka pom

     1        <dependencies>
     2         <dependency>
     3             <groupId>com.google.code.gson</groupId>
     4             <artifactId>gson</artifactId>
     5             <version>2.8.5</version>
     6         </dependency>
     7 
     8         <dependency>
     9             <groupId>org.springframework.cloud</groupId>
    10             <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
    11             <version>2.1.0.RELEASE</version>
    12         </dependency>    
    13         
    14         <dependency>
    15             <groupId>junit</groupId>
    16             <artifactId>junit</artifactId>
    17             <version>4.11</version>
    18             <scope>test</scope>
    19         </dependency>

    3. yml 配置

    server:
      port: 7001
    
    eureka:
      instance:
        hostname: localhost  #eureka服务器的实例名称
      client:
        register-with-eureka: false  #表示不想注册中心注册自己
        fetch-registry: false  #表示自己就是注册中心
        service-url:
          defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/    #设置与eureka server交互的地址查询服务

    客户端向服务端每30s 发送一次心跳,90s 之后客户端如果没有发送心跳,Service 会去除这个客户端

    4.启动类

    package com.service;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
    
    @SpringBootApplication
    @EnableEurekaServer  //服务器启动类,接受其他微服务注册进来
    public class Dept_Eureka {
    
        public static void main(String[] args){
            SpringApplication.run(Dept_Eureka.class,args);
        }
    }
  • 相关阅读:
    志愿者招募 [NOI2008] [鬼畜网络流]
    莫队入门
    分块入门
    高速公路 [HAOI2012] [线段树]
    游历校园 [COGS 614] [欧拉图]
    网络吞吐量 [CQOI2015] [网络流]
    LeetCode 27. Remove Element
    LeetCode 26. Remove Duplicates from Sorted Array
    LeetCode 21. Merge Two Sorted Lists
    LeetCode 20. Valid Parentheses
  • 原文地址:https://www.cnblogs.com/mm163/p/10584228.html
Copyright © 2020-2023  润新知