服务集成sentinel&demo
parent
7c2597a908
commit
18137a4125
|
@ -36,6 +36,18 @@
|
|||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringCloud Alibaba Sentinel -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Sentinel Datasource Nacos -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.csp</groupId>
|
||||
<artifactId>sentinel-datasource-nacos</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Test 测试相关 -->
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.cloud</groupId>
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
package cn.iocoder.yudao.framework.sentinel.config;
|
||||
|
||||
import cn.iocoder.yudao.framework.sentinel.core.handler.SentinelExceptionHandler;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
/**
|
||||
* 当Spring容器中不存在MyService类型的bean时,才创建这个bean
|
||||
*/
|
||||
@AutoConfiguration
|
||||
@Slf4j
|
||||
public class SentinelExceptionHandlerAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public SentinelExceptionHandler sentinelExceptionHandler() {
|
||||
return new SentinelExceptionHandler();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package cn.iocoder.yudao.framework.sentinel.core.handler;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils;
|
||||
import com.alibaba.csp.sentinel.adapter.spring.webmvc_v6x.callback.BlockExceptionHandler;
|
||||
import com.alibaba.csp.sentinel.slots.block.BlockException;
|
||||
import com.alibaba.csp.sentinel.slots.block.authority.AuthorityException;
|
||||
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeException;
|
||||
import com.alibaba.csp.sentinel.slots.block.flow.FlowException;
|
||||
import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowException;
|
||||
import com.alibaba.csp.sentinel.slots.system.SystemBlockException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
|
||||
/**
|
||||
* Sentinel自定义阻断异常处理
|
||||
*/
|
||||
public class SentinelExceptionHandler implements BlockExceptionHandler {
|
||||
|
||||
@Override
|
||||
public void handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, String s, BlockException e) throws Exception {
|
||||
|
||||
String msg = "未知异常";
|
||||
int status = HttpStatus.TOO_MANY_REQUESTS.value();
|
||||
if (e instanceof FlowException) {
|
||||
msg = "请求限流";
|
||||
} else if (e instanceof ParamFlowException) {
|
||||
msg = "请求被热点参数限流";
|
||||
} else if (e instanceof DegradeException) {
|
||||
msg = "请求降级";
|
||||
} else if (e instanceof AuthorityException) {
|
||||
msg = "没有权限访问";
|
||||
status = HttpStatus.UNAUTHORIZED.value();
|
||||
}else if (e instanceof SystemBlockException) {
|
||||
msg = "系统规则限流或降级";
|
||||
}
|
||||
|
||||
ServletUtils.writeJSON(httpServletResponse, CommonResult.error(status, msg));
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
package cn.iocoder.yudao.framework.sentinel.core;
|
|
@ -1,4 +1,5 @@
|
|||
cn.iocoder.yudao.framework.idempotent.config.YudaoIdempotentConfiguration
|
||||
cn.iocoder.yudao.framework.lock4j.config.YudaoLock4jConfiguration
|
||||
cn.iocoder.yudao.framework.ratelimiter.config.YudaoRateLimiterConfiguration
|
||||
cn.iocoder.yudao.framework.signature.config.YudaoApiSignatureAutoConfiguration
|
||||
cn.iocoder.yudao.framework.signature.config.YudaoApiSignatureAutoConfiguration
|
||||
cn.iocoder.yudao.framework.sentinel.config.SentinelExceptionHandlerAutoConfiguration
|
|
@ -0,0 +1,23 @@
|
|||
package cn.iocoder.yudao.module.infra.api.demo;
|
||||
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.module.infra.api.demo.fallback.SentinelFeigenDemoFallback;
|
||||
import cn.iocoder.yudao.module.infra.enums.ApiConstants;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
|
||||
/**
|
||||
* sentinel Feign demo
|
||||
*/
|
||||
@FeignClient(name = ApiConstants.NAME, fallback = SentinelFeigenDemoFallback.class)
|
||||
public interface SentinelFeigenDemoApi {
|
||||
|
||||
String PREFIX = ApiConstants.PREFIX + "/provider/sentinel";
|
||||
|
||||
|
||||
@GetMapping(PREFIX +"/test/{message}")
|
||||
public CommonResult<String> providerSentinelTest(@PathVariable("message") String message);
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package cn.iocoder.yudao.module.infra.api.demo.fallback;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.module.infra.api.demo.SentinelFeigenDemoApi;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class SentinelFeigenDemoFallback implements SentinelFeigenDemoApi {
|
||||
|
||||
@Override
|
||||
public CommonResult<String> providerSentinelTest(String message) {
|
||||
return CommonResult.error(HttpStatus.TOO_MANY_REQUESTS.value(), "对方服务不可用,开始服务降级处理");
|
||||
}
|
||||
}
|
|
@ -147,6 +147,12 @@
|
|||
<artifactId>tika-core</artifactId> <!-- 文件客户端:文件类型的识别 -->
|
||||
</dependency>
|
||||
|
||||
<!-- 服务保障相关 TODO 芋艿:暂时去掉 -->
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.cloud</groupId>
|
||||
<artifactId>yudao-spring-boot-starter-protection</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
<build>
|
||||
<!-- 设置构建的 jar 包名 -->
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
package cn.iocoder.yudao.module.infra.api.demo;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
/**
|
||||
* 提供 RESTful API 接口,给 Feign 调用
|
||||
*/
|
||||
@RestController
|
||||
@Validated
|
||||
public class SentinelFeigenApiImpl implements SentinelFeigenDemoApi {
|
||||
|
||||
@Override
|
||||
public CommonResult<String> providerSentinelTest(String message) {
|
||||
return success("OK");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
package cn.iocoder.yudao.module.infra.controller.admin.demo.sentinel;
|
||||
|
||||
|
||||
import com.alibaba.csp.sentinel.annotation.SentinelResource;
|
||||
import com.alibaba.csp.sentinel.slots.block.BlockException;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.security.PermitAll;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* sentinel 示例
|
||||
* TODO 芋艿:考虑后续优化示例
|
||||
*/
|
||||
@Tag(name = "管理后台 - sentinel")
|
||||
@RestController
|
||||
@RequestMapping("/infra/sentinel/demo")
|
||||
@Validated
|
||||
public class SentinelDemoController {
|
||||
|
||||
@GetMapping("flow")
|
||||
@PermitAll
|
||||
public String flow(String userName){
|
||||
return "hello "+userName;
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联资源
|
||||
*/
|
||||
@GetMapping("flow-ref")
|
||||
@PermitAll
|
||||
public String flowRef(){
|
||||
return "hello flowRef";
|
||||
}
|
||||
|
||||
@GetMapping("degrade")
|
||||
@PermitAll
|
||||
public String degrade(String userName){
|
||||
return "hello "+userName;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按照资源名称的方式限流,并对限流流进行友好处理
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("getOrderNo")
|
||||
@SentinelResource(value = "getOrderNoResource",blockHandler = "getOrderNoBlockHandler",blockHandlerClass = SentinelDemoController.class)
|
||||
@PermitAll
|
||||
public String getOrderNo(HttpServletRequest request){
|
||||
return UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 限流后续操作方法
|
||||
* @param e
|
||||
* @return
|
||||
*/
|
||||
public static String getOrderNoBlockHandler(HttpServletRequest request, BlockException e){
|
||||
return "不好意思,前方拥挤,请您稍后再试";
|
||||
}
|
||||
|
||||
}
|
|
@ -15,6 +15,66 @@ spring:
|
|||
namespace: dev # 命名空间。这里使用 dev 开发环境
|
||||
group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP
|
||||
|
||||
--- #################### Sentinel相关配置 ####################
|
||||
spring:
|
||||
cloud:
|
||||
sentinel:
|
||||
enabled: true # 是否开启。默认为 true 开启
|
||||
eager: true # 是否饥饿加载。默认为 false 关闭
|
||||
transport:
|
||||
dashboard: 127.0.0.1:8080 # Sentinel 控制台地址
|
||||
filter:
|
||||
url-patterns: /** # 拦截请求的地址。默认为 /*
|
||||
# sentinel用nacos作为数据源的配置 (可导入/yudao-cloud/script/sentinel/gateway-server下对应规则,使用时需去掉注释)
|
||||
datasource:
|
||||
# 流控规则
|
||||
flow:
|
||||
nacos:
|
||||
server-addr: ${spring.cloud.nacos.server-addr}
|
||||
namespace: ${spring.cloud.nacos.discovery.namespace}
|
||||
username: ${spring.cloud.nacos.username}
|
||||
password: ${spring.cloud.nacos.password}
|
||||
data-id: ${spring.application.name}-flow-rules # 在修改的sentinel 源码中定义的规则名
|
||||
rule-type: flow
|
||||
# 降级规则
|
||||
degrade:
|
||||
nacos:
|
||||
server-addr: ${spring.cloud.nacos.server-addr}
|
||||
namespace: ${spring.cloud.nacos.discovery.namespace}
|
||||
username: ${spring.cloud.nacos.username}
|
||||
password: ${spring.cloud.nacos.password}
|
||||
dataId: ${spring.application.name}-degrade-rules
|
||||
rule-type: degrade
|
||||
# 授权规则
|
||||
# authority:
|
||||
# nacos:
|
||||
# server-addr: ${spring.cloud.nacos.server-addr}
|
||||
# namespace: ${spring.cloud.nacos.discovery.namespace}
|
||||
# username: ${spring.cloud.nacos.username}
|
||||
# password: ${spring.cloud.nacos.password}
|
||||
# dataId: ${spring.application.name}-authority-rules
|
||||
# rule-type: authority
|
||||
# # 热点规则
|
||||
# param-flow:
|
||||
# nacos:
|
||||
# server-addr: ${spring.cloud.nacos.server-addr}
|
||||
# namespace: ${spring.cloud.nacos.discovery.namespace}
|
||||
# username: ${spring.cloud.nacos.username}
|
||||
# password: ${spring.cloud.nacos.password}
|
||||
# dataId: ${spring.application.name}-param-flow-rules
|
||||
# rule-type: param-flow
|
||||
# # 系统规则
|
||||
# system:
|
||||
# nacos:
|
||||
# server-addr: ${spring.cloud.nacos.server-addr}
|
||||
# namespace: ${spring.cloud.nacos.discovery.namespace}
|
||||
# username: ${spring.cloud.nacos.username}
|
||||
# password: ${spring.cloud.nacos.password}
|
||||
# dataId: ${spring.application.name}-system-rules
|
||||
# groupId: DEFAULT_GROUP
|
||||
# data-type: json
|
||||
# rule-type: system
|
||||
|
||||
--- #################### 数据库相关配置 ####################
|
||||
spring:
|
||||
# 数据源配置项
|
||||
|
|
|
@ -4,8 +4,8 @@ spring:
|
|||
cloud:
|
||||
nacos:
|
||||
server-addr: 127.0.0.1:8848 # Nacos 服务器地址
|
||||
username: # Nacos 账号
|
||||
password: # Nacos 密码
|
||||
username: nacos # Nacos 账号
|
||||
password: nacos # Nacos 密码
|
||||
discovery: # 【配置中心】配置项
|
||||
namespace: dev # 命名空间。这里使用 dev 开发环境
|
||||
group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP
|
||||
|
@ -15,6 +15,66 @@ spring:
|
|||
namespace: dev # 命名空间。这里使用 dev 开发环境
|
||||
group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP
|
||||
|
||||
--- #################### Sentinel相关配置 ####################
|
||||
spring:
|
||||
cloud:
|
||||
sentinel:
|
||||
enabled: true # 是否开启。默认为 true 开启
|
||||
eager: true # 是否饥饿加载。默认为 false 关闭
|
||||
transport:
|
||||
dashboard: 127.0.0.1:8080 # Sentinel 控制台地址
|
||||
filter:
|
||||
url-patterns: /** # 拦截请求的地址。默认为 /*
|
||||
# sentinel用nacos作为数据源的配置 (可导入/yudao-cloud/script/sentinel/gateway-server下对应规则,使用时需去掉注释)
|
||||
datasource:
|
||||
# 流控规则
|
||||
flow:
|
||||
nacos:
|
||||
server-addr: ${spring.cloud.nacos.server-addr}
|
||||
namespace: ${spring.cloud.nacos.discovery.namespace}
|
||||
username: ${spring.cloud.nacos.username}
|
||||
password: ${spring.cloud.nacos.password}
|
||||
data-id: ${spring.application.name}-flow-rules # 在修改的sentinel 源码中定义的规则名
|
||||
rule-type: flow
|
||||
# 降级规则
|
||||
degrade:
|
||||
nacos:
|
||||
server-addr: ${spring.cloud.nacos.server-addr}
|
||||
namespace: ${spring.cloud.nacos.discovery.namespace}
|
||||
username: ${spring.cloud.nacos.username}
|
||||
password: ${spring.cloud.nacos.password}
|
||||
dataId: ${spring.application.name}-degrade-rules
|
||||
rule-type: degrade
|
||||
# 授权规则
|
||||
# authority:
|
||||
# nacos:
|
||||
# server-addr: ${spring.cloud.nacos.server-addr}
|
||||
# namespace: ${spring.cloud.nacos.discovery.namespace}
|
||||
# username: ${spring.cloud.nacos.username}
|
||||
# password: ${spring.cloud.nacos.password}
|
||||
# dataId: ${spring.application.name}-authority-rules
|
||||
# rule-type: authority
|
||||
# # 热点规则
|
||||
# param-flow:
|
||||
# nacos:
|
||||
# server-addr: ${spring.cloud.nacos.server-addr}
|
||||
# namespace: ${spring.cloud.nacos.discovery.namespace}
|
||||
# username: ${spring.cloud.nacos.username}
|
||||
# password: ${spring.cloud.nacos.password}
|
||||
# dataId: ${spring.application.name}-param-flow-rules
|
||||
# rule-type: param-flow
|
||||
# # 系统规则
|
||||
# system:
|
||||
# nacos:
|
||||
# server-addr: ${spring.cloud.nacos.server-addr}
|
||||
# namespace: ${spring.cloud.nacos.discovery.namespace}
|
||||
# username: ${spring.cloud.nacos.username}
|
||||
# password: ${spring.cloud.nacos.password}
|
||||
# dataId: ${spring.application.name}-system-rules
|
||||
# groupId: DEFAULT_GROUP
|
||||
# data-type: json
|
||||
# rule-type: system
|
||||
|
||||
--- #################### 数据库相关配置 ####################
|
||||
spring:
|
||||
|
||||
|
|
|
@ -165,6 +165,7 @@ yudao:
|
|||
enable: true
|
||||
ignore-urls:
|
||||
- /admin-api/infra/file/*/get/** # 获取图片,和租户无关
|
||||
- /admin-api/infra/sentinel/demo/** # sentinel demo
|
||||
ignore-tables:
|
||||
- infra_codegen_column
|
||||
- infra_codegen_table
|
||||
|
@ -178,3 +179,9 @@ yudao:
|
|||
- infra_data_source_config
|
||||
|
||||
debug: false
|
||||
|
||||
--- #################### 开启feign对sentinel的支持 ####################
|
||||
|
||||
feign:
|
||||
sentinel:
|
||||
enabled: true
|
|
@ -98,10 +98,10 @@
|
|||
</dependency>
|
||||
|
||||
<!-- 服务保障相关 TODO 芋艿:暂时去掉 -->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>cn.iocoder.cloud</groupId>-->
|
||||
<!-- <artifactId>yudao-spring-boot-starter-protection</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.cloud</groupId>
|
||||
<artifactId>yudao-spring-boot-starter-protection</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Test 测试相关 -->
|
||||
<dependency>
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
package cn.iocoder.yudao.module.system.controller.admin.demo;
|
||||
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.module.infra.api.demo.SentinelFeigenDemoApi;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.annotation.security.PermitAll;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
|
||||
@Tag(name = "管理后台 - Sentinel Feigen Demo")
|
||||
@RestController()
|
||||
@RequestMapping("/system/sentinel/demo")
|
||||
public class SentinelFeigenDemoController {
|
||||
|
||||
@Resource
|
||||
private SentinelFeigenDemoApi sentinelFeigenDemoApiService;
|
||||
|
||||
@GetMapping("/provider/{message}")
|
||||
@PermitAll
|
||||
public CommonResult<String> providerSentinelTest(@PathVariable("message") String message) {
|
||||
return sentinelFeigenDemoApiService.providerSentinelTest(message);
|
||||
}
|
||||
}
|
|
@ -1,12 +1,16 @@
|
|||
package cn.iocoder.yudao.module.system.framework.rpc.config;
|
||||
|
||||
import cn.iocoder.yudao.module.infra.api.config.ConfigApi;
|
||||
import cn.iocoder.yudao.module.infra.api.demo.SentinelFeigenDemoApi;
|
||||
import cn.iocoder.yudao.module.infra.api.demo.fallback.SentinelFeigenDemoFallback;
|
||||
import cn.iocoder.yudao.module.infra.api.file.FileApi;
|
||||
import cn.iocoder.yudao.module.infra.api.websocket.WebSocketSenderApi;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@EnableFeignClients(clients = {FileApi.class, WebSocketSenderApi.class, ConfigApi.class})
|
||||
@EnableFeignClients(clients = {FileApi.class, WebSocketSenderApi.class, ConfigApi.class, SentinelFeigenDemoApi.class})
|
||||
@Import({SentinelFeigenDemoFallback.class})
|
||||
public class RpcConfiguration {
|
||||
}
|
||||
|
|
|
@ -15,6 +15,67 @@ spring:
|
|||
namespace: dev # 命名空间。这里使用 dev 开发环境
|
||||
group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP
|
||||
|
||||
--- #################### Sentinel相关配置 ####################
|
||||
|
||||
spring:
|
||||
cloud:
|
||||
sentinel:
|
||||
enabled: true # 是否开启。默认为 true 开启
|
||||
eager: true # 是否饥饿加载。默认为 false 关闭
|
||||
transport:
|
||||
dashboard: 127.0.0.1:8080 # Sentinel 控制台地址
|
||||
filter:
|
||||
url-patterns: /** # 拦截请求的地址。默认为 /*
|
||||
# sentinel用nacos作为数据源的配置 (可导入/yudao-cloud/script/sentinel/system-server下对应规则,使用时需去掉注释)
|
||||
datasource:
|
||||
# 流控规则
|
||||
flow:
|
||||
nacos:
|
||||
server-addr: ${spring.cloud.nacos.server-addr}
|
||||
namespace: ${spring.cloud.nacos.discovery.namespace}
|
||||
username: ${spring.cloud.nacos.username}
|
||||
password: ${spring.cloud.nacos.password}
|
||||
data-id: ${spring.application.name}-flow-rules # 在修改的sentinel 源码中定义的规则名
|
||||
rule-type: flow
|
||||
# 授权规则
|
||||
authority:
|
||||
nacos:
|
||||
server-addr: ${spring.cloud.nacos.server-addr}
|
||||
namespace: ${spring.cloud.nacos.discovery.namespace}
|
||||
username: ${spring.cloud.nacos.username}
|
||||
password: ${spring.cloud.nacos.password}
|
||||
dataId: ${spring.application.name}-authority-rules
|
||||
rule-type: authority
|
||||
# 降级规则
|
||||
degrade:
|
||||
nacos:
|
||||
server-addr: ${spring.cloud.nacos.server-addr}
|
||||
namespace: ${spring.cloud.nacos.discovery.namespace}
|
||||
username: ${spring.cloud.nacos.username}
|
||||
password: ${spring.cloud.nacos.password}
|
||||
dataId: ${spring.application.name}-degrade-rules
|
||||
rule-type: degrade
|
||||
# 热点规则
|
||||
param-flow:
|
||||
nacos:
|
||||
server-addr: ${spring.cloud.nacos.server-addr}
|
||||
namespace: ${spring.cloud.nacos.discovery.namespace}
|
||||
username: ${spring.cloud.nacos.username}
|
||||
password: ${spring.cloud.nacos.password}
|
||||
dataId: ${spring.application.name}-param-flow-rules
|
||||
rule-type: param-flow
|
||||
# 系统规则
|
||||
system:
|
||||
nacos:
|
||||
server-addr: ${spring.cloud.nacos.server-addr}
|
||||
namespace: ${spring.cloud.nacos.discovery.namespace}
|
||||
username: ${spring.cloud.nacos.username}
|
||||
password: ${spring.cloud.nacos.password}
|
||||
dataId: ${spring.application.name}-system-rules
|
||||
groupId: DEFAULT_GROUP
|
||||
data-type: json
|
||||
rule-type: system
|
||||
|
||||
--- #################### 数据库相关配置 ####################
|
||||
spring:
|
||||
# 数据源配置项
|
||||
|
|
|
@ -15,6 +15,67 @@ spring:
|
|||
namespace: dev # 命名空间。这里使用 dev 开发环境
|
||||
group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP
|
||||
|
||||
--- #################### Sentinel相关配置 ####################
|
||||
|
||||
spring:
|
||||
cloud:
|
||||
sentinel:
|
||||
enabled: true # 是否开启。默认为 true 开启
|
||||
eager: true # 是否饥饿加载。默认为 false 关闭
|
||||
transport:
|
||||
dashboard: 127.0.0.1:8080 # Sentinel 控制台地址
|
||||
filter:
|
||||
url-patterns: /** # 拦截请求的地址。默认为 /*
|
||||
# sentinel用nacos作为数据源的配置 (可导入/yudao-cloud/script/sentinel/system-server下对应规则,使用时需去掉注释)
|
||||
datasource:
|
||||
# 流控规则
|
||||
flow:
|
||||
nacos:
|
||||
server-addr: ${spring.cloud.nacos.server-addr}
|
||||
namespace: ${spring.cloud.nacos.discovery.namespace}
|
||||
username: ${spring.cloud.nacos.username}
|
||||
password: ${spring.cloud.nacos.password}
|
||||
data-id: ${spring.application.name}-flow-rules # 在修改的sentinel 源码中定义的规则名
|
||||
rule-type: flow
|
||||
# 授权规则
|
||||
authority:
|
||||
nacos:
|
||||
server-addr: ${spring.cloud.nacos.server-addr}
|
||||
namespace: ${spring.cloud.nacos.discovery.namespace}
|
||||
username: ${spring.cloud.nacos.username}
|
||||
password: ${spring.cloud.nacos.password}
|
||||
dataId: ${spring.application.name}-authority-rules
|
||||
rule-type: authority
|
||||
# 降级规则
|
||||
degrade:
|
||||
nacos:
|
||||
server-addr: ${spring.cloud.nacos.server-addr}
|
||||
namespace: ${spring.cloud.nacos.discovery.namespace}
|
||||
username: ${spring.cloud.nacos.username}
|
||||
password: ${spring.cloud.nacos.password}
|
||||
dataId: ${spring.application.name}-degrade-rules
|
||||
rule-type: degrade
|
||||
# 热点规则
|
||||
param-flow:
|
||||
nacos:
|
||||
server-addr: ${spring.cloud.nacos.server-addr}
|
||||
namespace: ${spring.cloud.nacos.discovery.namespace}
|
||||
username: ${spring.cloud.nacos.username}
|
||||
password: ${spring.cloud.nacos.password}
|
||||
dataId: ${spring.application.name}-param-flow-rules
|
||||
rule-type: param-flow
|
||||
# 系统规则
|
||||
system:
|
||||
nacos:
|
||||
server-addr: ${spring.cloud.nacos.server-addr}
|
||||
namespace: ${spring.cloud.nacos.discovery.namespace}
|
||||
username: ${spring.cloud.nacos.username}
|
||||
password: ${spring.cloud.nacos.password}
|
||||
dataId: ${spring.application.name}-system-rules
|
||||
groupId: DEFAULT_GROUP
|
||||
data-type: json
|
||||
rule-type: system
|
||||
|
||||
--- #################### 数据库相关配置 ####################
|
||||
spring:
|
||||
# 数据源配置项
|
||||
|
|
|
@ -174,6 +174,7 @@ yudao:
|
|||
- /rpc-api/system/tenant/valid # 防止递归。避免调用 /rpc-api/system/tenant/valid 接口时,又去触发 /rpc-api/system/tenant/valid 去校验
|
||||
- /rpc-api/system/tenant/id-list # 获得租户列表的时候,无需传递租户编号
|
||||
- /rpc-api/system/oauth2/token/check # 访问令牌校验时,无需传递租户编号;主要解决上传文件的场景,前端不会传递 tenant-id!
|
||||
- /admin-api/system/sentinel/demo/provider/* # 示例演示,演示 Sentinel 熔断降级
|
||||
ignore-tables:
|
||||
- system_tenant
|
||||
- system_tenant_package
|
||||
|
@ -205,3 +206,9 @@ yudao:
|
|||
end-code: 9999 # 这里配置 9999 的原因是,测试方便。
|
||||
|
||||
debug: false
|
||||
|
||||
--- #################### 开启feign对sentinel的支持 ####################
|
||||
|
||||
feign:
|
||||
sentinel:
|
||||
enabled: true
|
Loading…
Reference in New Issue