[记录点滴]Spring Boot Admin源码分析笔记
[记录点滴]Spring Boot Admin源码分析笔记
0x00 摘要
本文是过去使用Spring Boot Admin时候分析源码的笔记。虽然比较简单,但是也可以看出Spring Boot Admin的实现思想。
0x01 如何使用
如何使用?
在你自己application中加入 @EnableAdminServer,就可以被监控到。
@EnableAdminServer的实现
@Import(AdminServerImportSelector.class) ----- 引入Spring Boot Admin的自动配置类
@EnableZuulServer -------------------------- Spring Boot Admin做了个gateway
public @interface EnableAdminServer {
}
@Import(AdminServerImportSelector.class)
其作用是导出配置:
NotifierConfiguration,
HazelcastStoreConfiguration,
AdminServerCoreConfiguration,
AdminServerWebConfiguration,
DiscoveryClientConfiguration,
RevereseZuulProxyConfiguration
0x02 configuration
以下是各种相关配置
- AdminServerCoreConfiguration 生成很多基础bean
- AdminServerWebConfiguration web相关的配置和bean,EventListener
- DiscoveryClientConfiguration 与client发现相关的bean
- NotifierConfiguration: NotifierListener,以及各种notify需要的配置:CompositeNotifierConfiguration,MailNotifierConfiguration。TelegramNotifierConfiguration......
- RevereseZuulProxyConfiguration 关于zuul的配置, 比如 ApplicationHeadersFilter,SimpleHostRoutingFilter... 因为SBA默认使用@EnableZuulServer
- HazelcastStoreConfiguration 暂时用不到,网格存储用的
0x03 几个关键类
以下是一些关键类
- ApplicationRegistry - 主要作用是: 响应各个service client的注册,生成一个application,然后放到 ApplicationStore中。很多地方会用到,比如 RegistryController 会调用它获取application列表, 获取某一个app details。
- ApplicationStore --- 存储application,可以从这里入手来进行mysql存储,比如自己写一个MysqlApplicationStore。
- SimpleApplicationStore -------- 就是一个内存map
- HazelcastApplicationStore ----- 开源的可扩展的内存数据网格
- ApplicationIdGenerator --- 就是产生个id
- AdminServerProperties --- 每个应用对应的属性,用来配置zuul路由
0x04 discovery
Spring Boot Admin 使用 Spring Clouds DiscoveryClient @EnableDiscoveryClient 来发现应用。
把org.springframework.cloud.client.ServiceInstance转换成Application。其中还获取了 instance.getMetadata().get(KEY_HEALTH_PATH); instance.getMetadata().get(KEY_MANAGEMENT_PATH);
ApplicationDiscoveryListener : 分别响应了以下消息来发现client
import org.springframework.cloud.client.discovery.event.HeartbeatEvent;
import org.springframework.cloud.client.discovery.event.InstanceRegisteredEvent;
import org.springframework.cloud.client.discovery.event.ParentHeartbeatEvent;
import org.springframework.boot.context.event.ApplicationReadyEvent;
如果收到了HeartbeatEvent,则在discover中,会通过 discoveryClient.getServices() 得到目前注册到eureka的服务名字列表,然后注册。
0x05 event
这是内部的各种event,发现了client之后就在内部进行消息传递,进行内部后续动作,比如updateStatus,更新application store
0x06 journal
数据结构
ApplicationEventJournal 就是用SimpleJournaledEventStore(list) 存储 ClientApplicationEvent
Web resource
使用SseEmitter实现了推送。
所谓的Sse其实就是Server-Sent Events,即服务器推送事件,属于HTML5的一项新功能,常用于服务器主动通知客户端有相关信息的更新。其他替代方法一般有WebSocket和客户端定时轮询,前者过于复杂,后者又过于低效而笨拙。SseEmitter属于ResponseBodyEmitter的子类,可以生成text/event-stream格式的信息。
会不停地往浏览器推送最新的journal。
0x07 Model
StatusInfo, Info 这两个类都在Application中存储。
StatusUpdateApplicationListener 会在 ApplicationReadyEvent/ContextClosedEvent/ClientApplicationRegisteredEvent 各种响应中进行update。
0x08 registry
ApplicationRegistry : 主要作用就是响应各个service client的注册,生成一个application,然后放到 ApplicationStore中。
RegistryController : REST controller for controlling registration of managed applications。也用来给浏览器获取applicaiton列表,application detail。
0x09 web
AdminController : 用来注释了几个类 RegistryController, NotificationFilterController
@Target({ ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface AdminController {
}
ApplicationOperations : Handles all rest operations invoked on a registered application. 对于info, health, 就是调用application中的对应url获取数据后转发。
[记录点滴]Spring Boot Admin源码分析笔记的更多相关文章
- Spring Boot缓存源码分析
前言 项目里面要增加一个应用缓存,原本想着要怎么怎么来整合ehcache和springboot,做好准备配置这个配置那个,结果只需要做三件事: pom依赖 写好一个ehcache的配置文件 在boot ...
- spring boot 入口源码分析
public ConfigurableApplicationContext run(String... args) { StopWatch stopWatch = new StopWatch(); / ...
- spring boot admin 源码包的编译
https://github.com/codecentric/spring-boot-admin 下载地址: 编译要求: Build Requirements: Node.js v8.x (LTS) ...
- Spring的IOC源码分析
Spring IOC 容器源码分析 Spring 最重要的概念是 IOC 和 AOP,本篇文章其实就是要带领大家来分析下 Spring 的 IOC 容器.既然大家平时都要用到 Spring,怎么可以不 ...
- Spring IOC 容器源码分析 - 循环依赖的解决办法
1. 简介 本文,我们来看一下 Spring 是如何解决循环依赖问题的.在本篇文章中,我会首先向大家介绍一下什么是循环依赖.然后,进入源码分析阶段.为了更好的说明 Spring 解决循环依赖的办法,我 ...
- Spring IOC 容器源码分析 - 创建单例 bean 的过程
1. 简介 在上一篇文章中,我比较详细的分析了获取 bean 的方法,也就是getBean(String)的实现逻辑.对于已实例化好的单例 bean,getBean(String) 方法并不会再一次去 ...
- Spring IOC 容器源码分析 - 获取单例 bean
1. 简介 为了写 Spring IOC 容器源码分析系列的文章,我特地写了一篇 Spring IOC 容器的导读文章.在导读一文中,我介绍了 Spring 的一些特性以及阅读 Spring 源码的一 ...
- spring boot @Value源码解析
Spring boot 的@Value只能用于bean中,在bean的实例化时,会给@Value的属性赋值:如下面的例子: @SpringBootApplication @Slf4j public c ...
- Spring Developer Tools 源码分析:三、重启自动配置'
接上文 Spring Developer Tools 源码分析:二.类路径监控,接下来看看前面提到的这些类是如何配置,如何启动的. spring-boot-devtools 使用了 Spring Bo ...
- Spring Developer Tools 源码分析:二、类路径监控
在 Spring Developer Tools 源码分析一中介绍了 devtools 提供的文件监控实现,在第二部分中,我们将会使用第一部分提供的目录监控功能,实现对开发环境中 classpath ...
随机推荐
- Redis循环慢接口优化
原慢接口 List<String> keys = new ArrayList<>(Arrays.asList("1", "2", &qu ...
- asp.net 简单日志收集
做开发的都知道,完整的日志记录对问题的解决,回溯是多么的重要,多么的不可缺少. 那么我们怎么记录完整的日志? 今天,我们来说一说问题:从哪里开始记录呢?在哪里保存呢? IHttpModule,这个大家 ...
- 【Kotlin】select简介
1 前言 协程的 select 是一种用于异步操作的选择器,它允许同时等待多个挂起函数的结果,并在其中一个完成时执行相应的操作. 能够被 select 的事件都是 SelectClause,在 ...
- Java基础 —— 集合(一)
集合(一) 数组和集合的区别 数组是固定长度的数据结构,而集合是动态的数据结构 数组可以包含基本数据类型和对象,集合只能包含对象 数组只能存放同一类型的数据,而集合可以蹲房不同类型的 数组可以直接访问 ...
- Tailwind CSS样式优先级控制
前情 Tailwind CSS 是一个原子类 CSS 框架,它将基础的 CSS 全部拆分为原子级别,能达到最小化项目CSS.它的工作原理是扫描所有 HTML 文件.JavaScript 组件以及任何模 ...
- 对象存储 AVIF 图片压缩,邀您参与免费内测!
对象存储 AVIF 图片压缩免费内测正式开放!AVIF 作为压缩图片中的新主力军,都有哪些特点呢?通过对象存储又要如何使用 AVIF 压缩呢?这篇文章将深入浅出的为您介绍~ 具体介绍 现在硬件设备越 ...
- Xcode Swift自动格式化
Xcode Swift自动格式化 安装SwiftFormat SwiftFormat 是一款用来格式化Swift代码的命令行工具. 直接用Homebrew安装 brew install swiftfo ...
- utf-8 - 如何修复 'character map file ` UTF-8' not found'
正在设置一个 UBI rhel8 容器.我需要执行这个命令: localedef -f UTF-8 -i en_US en_US.UTF-8 失败了: character map file `UTF- ...
- mac上遇到的错误sed command a expects followed by text
上简单的替换操作 sed -i 's/apple/mac/g' full-path-file 执行后报错,"sed: 1: command a expects \ followed by t ...
- Qt编写地图综合应用23-标注点交互
一.前言 地图项目应用中,标注点的交互使用频率非常高,这应该是最常用的场景,比如从数据库中读取出来设备的信息包括经纬度坐标,然后需要在地图上显示对应的设备,这就需要用addMarker函数来动态添加标 ...