Eureka:服务发现工具

Eureka:服务发现工具

一、Eureka介绍

1. 什么是Eureka

​ Eureka是由Netflix公司推出的服务注册和发现工具(Service Discovery,平时说的注册中心)

2. 包含注册中心的软件架构图

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ZH6phbrb-1662385167712)(images/eureka3.png)]

3. Eureka角色

​ Eureka中分为两个角色:Eureka Server(Eureka服务)和Eureka Client(Eureka客户端)。无论是服务端还是客户端其本质都是一个Java项目,在Spring Cloud中主要通过启动类上添加@EnableEurekaServer和@EnableEurekaClient(可以省略)来区分当前应用程序是服务端还是客户端。

3.1 Eureka Server

​ 可以理解成之前我们讲解的Zookeeper注册中心,只是现在使用的是Java项目实现的(Spring Cloud内嵌Eureka)。

3.2 Eureka Client

​ 可以理解成所有需要注册到Eureka Server中的应用。为什么需要向注册中心中注册呢?因为注册后别人才能通过注册中心获取到项目信息和项目所在服务器信息,通过这些信息调用这个项目。Spring Cloud中每个项目调用的信息都存储在了注册中心中(Eureka)。

3.2.1 Application Service

​ 应用服务端。是Eureka Client中的一个相对角色。

3.2.2 Application Client

​ 应用客户端。是Eureka Client中的一个相对角色。

注意:在这里,Spring Cloud中没有绝对的Application Service和Application Client说法。如果A项目访问B项目,称A项目为Application Client,称B项目为Application Service。同时可能存在C访问A的情况,这是C项目是Application Client,A项目是Application Service。发现A项目又是Application Service又是Application Client,主要看针对哪个业务场景。无论是Applicatin Service还是Application Client都是Eureka Client。

三、搭建单机版Eureka Server

​ 搭建Eureka Server时就相当于在安装Eureka软件。这是在Spring Cloud学习过程中接触的一种全新环境搭建方式,替换了之前需要安装、配置软件的问题。

1. POM依赖

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.3.12.RELEASE</version>
</parent>
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>Hoxton.SR12</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>
<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
    </dependency>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值