-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSentinelClientInit.java
59 lines (51 loc) · 1.6 KB
/
SentinelClientInit.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package com.sentinel.client.demo.config;
import com.alibaba.csp.sentinel.annotation.aspectj.SentinelResourceAspect;
import com.alibaba.csp.sentinel.init.InitExecutor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.annotation.PostConstruct;
/**
* @Description 初始化Sentinel配置
*/
@Slf4j
@Configuration
public class SentinelClientInit {
@Autowired
private SentinelUtil sentinelUtil;
/**
* 初始化aop
*
* @return
*/
@Bean
public SentinelResourceAspect sentinelResourceAspect() {
return new SentinelResourceAspect();
}
/**
* 初始化sentinel配置
* 需要在{@link SentinelDatasourceProperty}中配置数据源
*/
@PostConstruct
public void init() {
SentinelClientConfigEntity entity = sentinelUtil.queryClientConfigEntity();
if (entity == null) {
return;
}
//初始化
InitExecutor.doInit();
//============加载配置项============
//单机流控
sentinelUtil.loadRule_flow(entity);
//熔断
sentinelUtil.loadRule_degrade(entity);
//集群流控
sentinelUtil.loadRule_flow_cluster(entity);
//系统规则
sentinelUtil.loadRule_system(entity);
//授权规则
sentinelUtil.loadRule_authority(entity);
log.info("---------- 容灾组件Sentinel Init Success:{} ----------", sentinelUtil.getCurrentMachineId());
}
}