-
Notifications
You must be signed in to change notification settings - Fork 51
tony component
徐植君 edited this page Dec 23, 2021
·
5 revisions
- 捕获异常并飞书通知
- 线程变量注解
<dependency>
<groupId>com.tony</groupId>
<artifactId>tony-component-spring-boot-starter</artifactId>
<version>1.0.4-SNAPSHOT</version>
</dependency>
risk:
tony:
component:
pointcut: execution(* cn.tony.component.test..*.*(..))
lark:
webhooks: https://open.feishu.cn/open-apis/bot/v2/hook/xxxx-xxxxx
kibana:
url: https://kibana域名/app/kibana#/discover
sname: xl-risk-jsticker-svc
stype: javadaemon
pointcut:要捕获异常的包范围
- 捕获全局异常并飞书通知
引入上面依赖,即拥有这个功能,
- 发送异常自定义飞书通知
@Lark(titleName = "短信发送失败", color = "green")
public void send(){
//dosomething
}
- 方法内部使用飞书通知
@Resource
LarkTemplate larkTemplate;
public boolean monthlyPay() {
try {
//do something
} catch (Exception e) {
log.error("失败了");
larkTemplate.send("每月车贴奖励支付失败", stickerContract, e.toString(), "red");
}
return true;
}
一个注解即可
@ThreadLocalCache
public DriverBO getDriverBO(long driverId) {
//do something
}
- 如果是web请求,请求链路结束自动清理ThreadLocal(ThreadLocalCacheFilter会执行清理动作)
- 如果是定时任务,没有Filter,则需要指定在哪个方法执行结束之后清理ThreadLocal,可通过
@ThreadLocalCleanAfter
指定:
@ThreadLocalCleanAfter
public void handle(){
System.out.println("do something");
}
因为,如果执行 @ThreadLocalCache注解的方法
和 执行 @ThreadLocalCleanAfter注解的方法
不是同一个线程,存在OOM的风险