[记录点滴]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源码分析笔记的更多相关文章

  1. Spring Boot缓存源码分析

    前言 项目里面要增加一个应用缓存,原本想着要怎么怎么来整合ehcache和springboot,做好准备配置这个配置那个,结果只需要做三件事: pom依赖 写好一个ehcache的配置文件 在boot ...

  2. spring boot 入口源码分析

    public ConfigurableApplicationContext run(String... args) { StopWatch stopWatch = new StopWatch(); / ...

  3. spring boot admin 源码包的编译

    https://github.com/codecentric/spring-boot-admin 下载地址: 编译要求: Build Requirements: Node.js v8.x (LTS) ...

  4. Spring的IOC源码分析

    Spring IOC 容器源码分析 Spring 最重要的概念是 IOC 和 AOP,本篇文章其实就是要带领大家来分析下 Spring 的 IOC 容器.既然大家平时都要用到 Spring,怎么可以不 ...

  5. Spring IOC 容器源码分析 - 循环依赖的解决办法

    1. 简介 本文,我们来看一下 Spring 是如何解决循环依赖问题的.在本篇文章中,我会首先向大家介绍一下什么是循环依赖.然后,进入源码分析阶段.为了更好的说明 Spring 解决循环依赖的办法,我 ...

  6. Spring IOC 容器源码分析 - 创建单例 bean 的过程

    1. 简介 在上一篇文章中,我比较详细的分析了获取 bean 的方法,也就是getBean(String)的实现逻辑.对于已实例化好的单例 bean,getBean(String) 方法并不会再一次去 ...

  7. Spring IOC 容器源码分析 - 获取单例 bean

    1. 简介 为了写 Spring IOC 容器源码分析系列的文章,我特地写了一篇 Spring IOC 容器的导读文章.在导读一文中,我介绍了 Spring 的一些特性以及阅读 Spring 源码的一 ...

  8. spring boot @Value源码解析

    Spring boot 的@Value只能用于bean中,在bean的实例化时,会给@Value的属性赋值:如下面的例子: @SpringBootApplication @Slf4j public c ...

  9. Spring Developer Tools 源码分析:三、重启自动配置'

    接上文 Spring Developer Tools 源码分析:二.类路径监控,接下来看看前面提到的这些类是如何配置,如何启动的. spring-boot-devtools 使用了 Spring Bo ...

  10. Spring Developer Tools 源码分析:二、类路径监控

    在 Spring Developer Tools 源码分析一中介绍了 devtools 提供的文件监控实现,在第二部分中,我们将会使用第一部分提供的目录监控功能,实现对开发环境中 classpath ...

随机推荐

  1. JVM源码分析-Java运行

    最近在看Java并发编程实践和Inside JVM两本书,发现如果不真正的了解底层运作,那么永远是雾里看花.因此从http://openjdk.java.net/groups/hotspot/上下载了 ...

  2. ZCMU-1120

    就这样 #include<cmath> #include<cstdio> #include<iostream> using namespace std; int m ...

  3. uni-app PDA扫描

    1.前言 PDA扫码是工厂项目中是非常常见的功能,这里记录下工作中的开发思路和模板,仅供参考 PDA扫码模式:模拟输入和广播模式 模拟输入:模拟键盘输入,一般后面会设置追加一个回车,优点是通用型强,缺 ...

  4. 【前端】‘opencollective-postinstall‘ 不是内部或外部命令,也不是可运行的程序

    问题 'opencollective-postinstall' 不是内部或外部命令,也不是可运行的程序 解决办法 npm install --save opencollective-postinsta ...

  5. 真正“搞”懂HTTPS协议19之HTTPS优化

    这是本系列的最后一篇了,其实本篇的内容也跟前两篇TLS的握手和优化有关系.其实HTTPS的核心就是TLS的明文握手连接,前两篇我们花了很大的篇幅来聊这些,另外一个就是在TLS握手完成后的密文传输部分了 ...

  6. 修改QScrollArea背景色透明,且不影响子控件,在Edit Style Sheet中修改

    在QScrollArea或者父控件中设置: QScrollArea{ background-color:transparent; } 在scrollAreaWidgetContents控件或者父控件中 ...

  7. ThreeJs-07操控物体实现家具编辑器

    本章节实现效果,通过gui快速添加场景,家具,并且可以快速设置家具实现一个编辑器效果 一.基础设置与物体添加列表 用之前做过的一个案例来改 首先不要这个模型,然后换个背景颜色,并且添加一个网格辅助器 ...

  8. 我们为什么选择Vue.js而不是React(转载)

    这篇非常好,可以当做 why React sucks 看 ;D 其实 vue 也不如 molecule 最近,Qwintry开发团队把很多项目都迁移至Vue.js,包括所有遗留的项目和新开始的项目: ...

  9. 【前端】【JavaScript】简单的加减乘除计算器

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. 【前端】display:inline-block中间的间隙

    父元素宽度800px 两个并列子元素宽度设为50%,并且使用了display:inline-block 结果一运行,两个元素不在同一行? 我查审元素,两个子元素div的宽度都是400,也没有边框,边距 ...