Eureka是什么

Eureka是Netflix的一 个子模块,也是核心模块之一- 。Eureka是一 个基于REST的服务,用于定位服务,以实现云端中间层服务发现和故障转移。服务注册与发现对于微服务架构来说是非常重要的,有了服务发现与注册,只需要使用服务的标识符,就可以访问到服务,而不需要修改服务调用的配置文件了。功能类似于dubbo的注册中心,比如Zookeeper。

Eureka的基本结构

SpringCloud封装了Netflix公司开发的Eureka模块来实现服务注册和发现。

Eureka采用了C-S的设计架构。Eureka Server作为服务注册功能的服务器,它是服务注册中心。

而系统中的其他微服务,使用Eureka的客户端连接到Eureka Server并维护心跳连接。这样系统的维护人员就可以通过Eureka Server来监控系统中各个微服务是否正常运行。SpringCloud的一些其他模块(比如Zuul)就可以通过Eureka Server来发现系统中的其他微服务,并执行相关的逻辑。

EurekaDubbo的架构对比

   

 

Eureka包含两个组件:Eureka Server和Eureka Client

Eureka Server提供服务注册服务;

各个节点启动后,会在EurekaServer中进行注册,这样EurekaServer中的服务注册表中将会储存所有可用服务节点的信息,服务节点的信息可以在界面中直观的看到;

EurekaClient是一个java客户端,用户简化Eureka Server的交互,客户端同时也具备一个内置的,使用轮询(round-robin)负载算法的负载均衡器。在应用启动后,将会向Eureka Server发送心跳(默认周期为30秒)。如果Eureka Server在多个心跳周期内没有接口到某个节点的心跳,EurekaServer将会从服务注册表中把这个服务节点移除(默认90秒);

Eureka实例

  pom.xml文件

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

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.junit.vintage</groupId>
                <artifactId>junit-vintage-engine</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
<!--eureka依赖--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> </dependency> </dependencies>

  applicatio.yml文件

server:
  port: 1001
eureka:
  client:
    ##不向服务中心注册自己
    register-with-eureka: false
    ##表明自己是注册中心
    fetch-registry: false
    #配置客户端访问的地址
    service-url:
      defaultZone: http://localhost:1001/eureka
  instance:
    #eureka服务端的实例名称
    hostname: eureka1001.com

  启动类

@SpringBootApplication
@EnableEurekaServer     //服务注册中心
public class SpringcloudEurekaServerApplication {

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

}

  页面效果

·····

 posted on 2019-12-17 17:45  wnwn  阅读(218)  评论(0编辑  收藏  举报