提交 388e29f8 编写于 作者: 郝先瑞

feat: 实验室整合Sentinel和添加限流接口

上级 aeb467bf
...@@ -133,6 +133,18 @@ ...@@ -133,6 +133,18 @@
<groupId>com.youlai</groupId> <groupId>com.youlai</groupId>
<artifactId>common-mybatis</artifactId> <artifactId>common-mybatis</artifactId>
</dependency> </dependency>
<!-- Sentinel流量控制、熔断降级 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
<!-- Sentinel规则持久化至Nacos配置 -->
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-datasource-nacos</artifactId>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
...@@ -15,7 +15,7 @@ import org.springframework.web.bind.annotation.*; ...@@ -15,7 +15,7 @@ import org.springframework.web.bind.annotation.*;
* @date 2022/4/16 20:46 * @date 2022/4/16 20:46
*/ */
@Api(tags = "「实验室」Seata接口模拟") @Api(tags = "「实验室」Seata接口")
@RestController @RestController
@RequestMapping("/api/v1/seata") @RequestMapping("/api/v1/seata")
@RequiredArgsConstructor @RequiredArgsConstructor
......
package com.youlai.lab.sentinel;
/**
* @author haoxr
* @date 2021/11/28 10:06
*/
public class Test {
}
package com.youlai.lab.sentinel.controller; package com.youlai.lab.sentinel.controller;
import com.youlai.common.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Arrays;
import java.util.List;
@Api(tags = "「实验室」Sentinel接口")
@RestController
@RequestMapping("/api/v1/sentinel")
@RequiredArgsConstructor
@Slf4j
public class SentinelController { public class SentinelController {
@ApiOperation("【限流】获取订单列表")
@GetMapping("/orders/_limit")
public Result listOrders() {
List<String> orderList = Arrays.asList("订单1", "订单2", "订单3");
return Result.success(orderList);
}
} }
...@@ -15,10 +15,24 @@ spring: ...@@ -15,10 +15,24 @@ spring:
server-addr: http://localhost:8848 server-addr: http://localhost:8848
# 配置中心 # 配置中心
config: config:
server-addr: http://c.youlai.tech:8848 server-addr: http://localhost:8848
file-extension: yaml file-extension: yaml
# 公共配置 # 公共配置
shared-configs[0]: shared-configs[0]:
data-id: youlai-common.yaml data-id: youlai-common.yaml
refresh: true refresh: true
sentinel:
enabled: true
eager: true # 取消控制台懒加载,项目启动即连接Sentinel
transport: # 提供客户端与服务端基础和监控API模块
dashboard: localhost:8858 # 控制台地址
datasource:
# 限流规则,flow为key,随便定义
flow:
nacos:
server-addr: ${spring.cloud.nacos.discovery.server-addr}
namespace: sentinel-namespace-id
dataId: ${spring.application.name}-flow-rules
groupId: SENTINEL_GROUP
data-type: json
rule-type: flow
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册