[记录点滴]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. 前端项目部署之pushstate-server

    pushstate-server 内部的原理是通过 connect 服务器,开启一个端口,将 dist/index.html 文件作为静态模板输出 这种方式可以将本地的项目打包成静态文件,以服务的方式 ...

  2. mongo之常见问题

    最近发现服务器上的MongoDB由于oom导致服务被杀死 1.查看oom时间 grep "Out of memory" /var/log/message 或者 dmesg -T|g ...

  3. 超详细 HarmonyOS 开发教程之开发环境搭建指南

    HarmonyOS开发环境搭建指南:DevEco Studio安装教程 一.系统要求 操作系统:Windows 10 64位或更高版本 RAM:至少8GB,推荐16GB 硬盘空间:至少10GB可用空间 ...

  4. postgres 在centos 安装

    执行如下命令安装POSTGRES sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86 ...

  5. Visual Studio 2017 rc 资源文件 预处理 宏 无效

    在属性c++下的预处理宏不会影响rc资源文件的,需要对rc资源文件单独设置. 右键rc资源文件,点击属性,在预处理器定义添加需要的宏

  6. 一图归纳三大种类矩阵范数:诱导范数,元素范数,Schatten范数,涵盖谱范数,2范数

    转载自:https://blog.csdn.net/qq_27261889/article/details/87902480

  7. arch linux deepin-wine-wechat

    https://aur.archlinux.org/packages/deepin-wine-wechat md5sum for WeChatSetup-3.9.0.28.exe should be ...

  8. Qt音视频开发40-ffmpeg采集桌面并录制

    一.前言 之前用ffmpeg打通了各种视频文件和视频流以及本地摄像头设备的采集,近期有个客户需求要求将整个桌面屏幕采集下来,并可以录制保存成MP4文件,以前也遇到过类似的需求,由于没有搞过,也没有精力 ...

  9. Qt音视频开发12-mpv解码播放

    一.前言 之前玩了vlc解码和ffmpeg解码,前阵子有个客户需要换成mpv解码,于是研究了下mpv的使用方法,自从用了mpv以后发现爱不释手,这玩意天生适合极客和程序员啊,居然将各种处理封装成了命令 ...

  10. Mac系统Obsidian和Typora更换霞鹜文楷字体

    在github上发现了一款非常好看的字体LXGW WenKai / 霞鹜文楷,这里记录下Mac电脑如何安装这个字体,以及我用到的笔记软件更换字体的过程. Mac安装字体 # 增加代理,不加代理下载速度 ...