zoukankan      html  css  js  c++  java
  • 服务注册与发现

    Spring Cloud使用演示版本

    Edgware.SR5版本,Spring Cloud 1.xxx版本。如果使用Spring Cloud 2.xxx版本,请注意有些依赖的变化。从Finchley版本之后,进入Spring Cloud 2.xxx。

    [Spring Cloud 管理依赖链接](https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-dependencies )

    概述

    需要用到组件是Spring Cloud Netflix的Eureka,Eureka是一个服务注册与发现模块

    创建服务注册中心

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

    启动类

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

    /**
    * Eureka registry center application
    **/
    @EnableEurekaServer
    @SpringBootApplication
    public class EurekaRegistryApplication {

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

    application.yml

    Eureka 是一个高可用的组件,它没有后端缓存,每一个实例注册之后需要向注册中心发送心跳(因此可以在内存中完成),在默认情况下 Erureka Server 也是一个 Eureka Client ,必须要指定一个 Server。


    server:
    port: 1111


    eureka:
    server:
      enable-self-preservation: false #关闭保护机制
      eviction-interval-timer-in-ms: 3000 #剔除失效服务间隔(默认60s)
    instance:
      hostname: localhost
    client:
      register-with-eureka: false #该应用是注册中心,代表不向注册中心注册自己
      fetch-registry: false #由于注册中心职责是维护服务实例,它并不需要检索服务
      serviceUrl:
        defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
      healthcheck:
        enabled: true


    spring:
    application:
      name: eureka-registry

    操作界面

    Eureka Server是有界面,启动工程,访问:http://localhost:1111

  • 相关阅读:
    [转]用汇编实现原子操作
    贪心算法练习集
    链表练习题集
    STL测试3)优先级队列实现二叉堆
    STL测试2)计算器简单实现
    STL测试
    Java学习笔记(三)
    【JAVA】学习笔记(2)
    【Java】学习笔记(1)
    【机器学习】异常检测算法(I)
  • 原文地址:https://www.cnblogs.com/liuenyuan1996/p/10281602.html
Copyright © 2011-2022 走看看