一、背景 告警模块,作为大多数应用都存在的一个基础功能,今天我们就以开源项目openjob 为例,分析其设计及实现。 首先,我们梳理一下需求: 支持多种告警方式,包括钉钉、飞书、微信和webhook。 方便业务模块的接入,这里采用本地事件驱动的方式来解耦模块间的依赖。 本文将针对这两个问题,先画出多个告警的类及接口设计,再讲述本地事件驱动,最后是异步消费队列中的任务。 二、接口及类的设计 源码内容就不在这里赘述了。 四个实现类的差异在于方法send()和channel(),大多数公共的实现在抽象类AbstractChannel中。 三、模块架构图 我们可以看到,通过本地事件驱动机制,告警模块和其他业务模块做到了解耦。 事件监听者,订阅事件,转换为任务存入到LinkedBlockingQueue队列中。 同时,启动两个线程池(pullExecutor线程池负责拉取队列中的任务,consumerExecutor线程池负责执行任务,也即告警) 还有两个基础类...
Is this you? As a journalist, you can create a free Muck Rack account to customize your profile, list your contact preferences, and upload a portfolio of your best work.
Claim your profile
Get in touch with Import Org.springframework.lang.
Contact Import Org.springframework.lang., search articles and posts on X, monitor coverage, and track replies from one place.
Learn more about Muck Rack