首页 > 其他分享 >Netflix的eureka注册中心简单使用

Netflix的eureka注册中心简单使用

时间:2023-10-02 18:55:17浏览次数:35  
标签:Netflix springframework eureka client 注册 org server cloud

使用

服务端

<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
server:
  port: 9000
  servlet:
    context-path: /eureka-server

eureka:
  instance:
    hostname: localhost   # eureka 实例名称
  client:
    register-with-eureka: false # 不向注册中心注册自己
    fetch-registry: false       # 是否检索服务
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {
    public static void main(String[] args) {
        SpringApplication.run(EurekaServerApplication.class);
    }
}

http://localhost:9000/eureka-server/

image

客户端

<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
server:
  port: 8092
  servlet:
    context-path: /demo-eureka-client

eureka:
  instance:
    instance-id: demo-eureka-client2
    prefer-ip-address: true # 访问路径可以显示 IP
  client:
    service-url:
      defaultZone: http://localhost:9000/eureka-server/eureka  # 注册中心访问地址
spring:
  application:
    name: demo-eureka-client

可以通过修改端口号和实例ID(instance-id)的值,使一个应用在本地运行多个实例

image

@SpringBootApplication
public class EurekaClientApplication {

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

}

原理分析

客户端

客户端通过AbstractJerseyEurekaHttpClient及子类JerseyReplicationClient来向注册中心发送请求,如注册实例,更新状态等

http://localhost:9000/eureka-server/eureka/apps/  GET   # 用来查询所有服务

服务端

使用Jersey来实现REST服务接口,如ApplicationsResource。EurekaServerAutoConfiguration中的jerseyFilterRegistration()方法定义了一个过滤器ServletContainer,类似SpringMVC的DispatcherServlet,做请求的分发,jerseyApplication()方法创建DefaultResourceConfig对象,使用Spring的类扫描来代替Jersey的扫描。

参考

Spring Cloud Eureka 源码解析

标签:Netflix,springframework,eureka,client,注册,org,server,cloud
From: https://www.cnblogs.com/strongmore/p/17131293.html

相关文章

  • 失业良久,开始注册一个订阅号分享自己的心理历程
                ......
  • Windows注册表
    Windows注册表1.2.3.4.5.6.7.8.9.10.当没有项时,可以自行创建,并往其添加值即可。在新建项时,项名称需要首字母大写。11.12.13.备份注册表时,找到对应的项选择导出即可。导出之后的文件扩展名为.reg。(这与早期的.ini文件不同)14.15.......
  • Applescript成功实现imessage数据筛选,imessage蓝号检测,无痕检测手机号是否注册imess
    一、imessages数据检测的两种方式:1.人工筛选,将要验证的号码输出到文件中,以逗号分隔。再将文件中的号码粘贴到iMessage客户端的地址栏,iMessage客户端会自动逐个检验该号码是否为iMessage账号,检验速度视网速而定。红色表示不是iMessage账号,蓝色表示iMessage账号。2.编写苹果MacOs......
  • NodeJS分别实现token、cookie登录注册鉴权(KOA2)
    源码https://github.com/NaCl-131/node-study.git包npminstallkoanpminodemon-D#保存自动更新npmikoa-router#路由npmikoa-body#解析post的传参npmimysql2sequelize#mysql和一个ORM工具npmijsonwebtoken#JWTnpmidotenv#.env文件npmikoa-sess......
  • 用html写用户注册与登录
    <!DOCTYPEhtml><html><head><title>RegistrationSystem</title><style>body{font-family:Arial,sans-serif;margin:0;padding:20px;}h1{text......
  • 视频监控系统/视频汇聚平台EasyCVR有下级平台注册时出现断流情况该如何排查解决?
    视频汇聚/视频云存储/集中存储/视频监控管理平台EasyCVR能在复杂的网络环境中,将分散的各类视频资源进行统一汇聚、整合、集中管理,实现视频资源的鉴权管理、按需调阅、全网分发、云存储、智能分析等,视频智能分析平台EasyCVR融合性强、开放度高、部署轻快,在智慧工地、智慧园区、智慧......
  • 单例注册表模式探索
    MazeFactory单例工厂,维护一个单例注册表,每种迷宫子类维护一个单例,这种方式不用破坏原来的代码结构,将单例实现搬到外面,如果维持全局的单例,无论属于何种迷宫均算作一种,,那么就需要提供迷宫的销毁方法,并在getInstance方法中控制单例的交替。还有一种方式是将每个子类设计为单例模式,并......
  • 视频监控系统/视频汇聚平台EasyCVR有下级平台注册时出现断流情况该如何排查解决?
    视频汇聚/视频云存储/集中存储/视频监控管理平台EasyCVR能在复杂的网络环境中,将分散的各类视频资源进行统一汇聚、整合、集中管理,实现视频资源的鉴权管理、按需调阅、全网分发、云存储、智能分析等,视频智能分析平台EasyCVR融合性强、开放度高、部署轻快,在智慧工地、智慧园区、智慧......
  • Applescript脚本实现全自动无痕检测手机号码是否注册iMessage的原理
    一、检测数据的两种方式:1.人工筛选,将要验证的号码输出到文件中,以逗号分隔。再将文件中的号码粘贴到iMessage客户端的地址栏,iMessage客户端会自动逐个检验该号码是否为iMessage账号,检验速度视网速而定。红色表示不是iMessage账号,蓝色表示iMessage账号。2.编写脚本控制Macos/iphon......
  • nacos注册服务时网卡选择错误的问题解决方案
    nacos注册服务时网卡选择错误的问题解决方案如果本地或者服务器有安装虚拟机或者虚拟网卡,会导致应用注册nacos注册中心,导致ip错误的问题,解决方案就是在应用中增加对应配置spring:cloud:inetutils:preferredNetworks:-192.168......