Skip to content

Commit

Permalink
sentinel规则集成到nacos
Browse files Browse the repository at this point in the history
  • Loading branch information
zhoutaoo committed Feb 5, 2024
1 parent 497f3bb commit d060448
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 17 deletions.
28 changes: 19 additions & 9 deletions opensabre-starter-rpc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,15 @@
</dependencyManagement>

<dependencies>
<dependency>
<groupId>io.github.opensabre</groupId>
<artifactId>opensabre-starter-register</artifactId>
</dependency>
<!-- 服务调用客户端 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<!--服务调用熔断降级-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
<!-- 服务调用负载 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
Expand All @@ -46,6 +45,21 @@
<groupId>io.github.openfeign</groupId>
<artifactId>feign-hc5</artifactId>
</dependency>
<!--服务调用熔断降级-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
<!--服务调用熔断降级规则数据源-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-sentinel-datasource</artifactId>
</dependency>
<!-- Sentinel数据源之 Nacos -->
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-datasource-nacos</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
<dependency>
<groupId>com.google.guava</groupId>
Expand All @@ -61,9 +75,5 @@
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>io.github.opensabre</groupId>
<artifactId>opensabre-starter-boot</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -23,37 +23,37 @@ public class SentinelExceptionHandlerAdvice {

@ExceptionHandler(BlockException.class)
public Result blockException(BlockException e) {
log.error("block exception:{}", e.getMessage());
log.error("block exception:{}", e.getRule());
return Result.fail(SystemErrorType.SYSTEM_BUSY);
}

@ExceptionHandler(FlowException.class)
public Result flowException(FlowException e) {
log.error("flow exception:{}", e.getMessage());
log.error("flow exception:{}", e.getRule());
return Result.fail(SystemErrorType.SYSTEM_BUSY);
}

@ExceptionHandler(DegradeException.class)
public Result degradeException(DegradeException e) {
log.error("degrade exception:{}", e.getMessage());
log.error("degrade exception:{}", e.getRule());
return Result.fail(SystemErrorType.SYSTEM_BUSY);
}

@ExceptionHandler(ParamFlowException.class)
public Result paramFlowException(ParamFlowException e) {
log.error("param flow exception:{}", e.getMessage());
log.error("param flow exception:{}", e.getRule());
return Result.fail(SystemErrorType.SYSTEM_BUSY);
}

@ExceptionHandler(SystemBlockException.class)
public Result systemBlockException(SystemBlockException e) {
log.error("system block exception:{}", e.getMessage());
log.error("system block exception:{}", e.getRule());
return Result.fail(SystemErrorType.SYSTEM_BUSY);
}

@ExceptionHandler(AuthorityException.class)
public Result authorityException(AuthorityException e) {
log.error("authority exception:{}", e.getMessage());
log.error("authority exception:{}", e.getRule());
return Result.fail(SystemErrorType.SYSTEM_BUSY);
}
}
11 changes: 9 additions & 2 deletions opensabre-starter-rpc/src/main/resources/opensabre-rpc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@ feign:
default:
connectTimeout: 5000
readTimeout: 10000
loggerLevel: BASIC
loggerLevel: basic
spring:
cloud:
sentinel:
enabled: true
enabled: true
datasource:
opensabre:
nacos:
serverAddr: ${REGISTER_HOST:localhost}:${REGISTER_PORT:8848}
groupId: DEFAULT_GROUP
dataId: ${spring.application.name}-rules
ruleType: flow

0 comments on commit d060448

Please sign in to comment.