Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
有来技术
youlai-mall
提交
17626703
Y
youlai-mall
项目概览
有来技术
/
youlai-mall
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
youlai-mall
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
17626703
编写于
7月 25, 2022
作者:
郝
郝先瑞
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: 重新整合Sentinel网关和普通流控
上级
c4eb9fa5
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
51 addition
and
10 deletion
+51
-10
youlai-gateway/Dockerfile
youlai-gateway/Dockerfile
+1
-1
youlai-gateway/pom.xml
youlai-gateway/pom.xml
+2
-1
youlai-gateway/src/main/java/com/youlai/gateway/sentinel/SentinelConfiguration.java
...va/com/youlai/gateway/sentinel/SentinelConfiguration.java
+32
-0
youlai-lab/src/main/java/com/youlai/lab/sentinel/controller/SentinelController.java
...om/youlai/lab/sentinel/controller/SentinelController.java
+16
-8
未找到文件。
youlai-gateway/Dockerfile
浏览文件 @
17626703
...
...
@@ -11,7 +11,7 @@ VOLUME /tmp
# 复制jar至镜像
ADD
target/youlai-gateway.jar app.jar
ENTRYPOINT
["java", "-Xmx128m", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/app.jar"]
ENTRYPOINT
["java", "-Xmx128m", "-Djava.security.egd=file:/dev/./urandom",
"-Dcsp.sentinel.app.type=1",
"-jar", "/app.jar"]
EXPOSE
9999
...
...
youlai-gateway/pom.xml
浏览文件 @
17626703
...
...
@@ -60,11 +60,12 @@
<artifactId>
spring-security-oauth2-jose
</artifactId>
</dependency>
<!-- Sentinel
流量控制、熔断降级
-->
<!-- Sentinel -->
<dependency>
<groupId>
com.alibaba.cloud
</groupId>
<artifactId>
spring-cloud-alibaba-sentinel-gateway
</artifactId>
</dependency>
<dependency>
<groupId>
com.alibaba.cloud
</groupId>
<artifactId>
spring-cloud-starter-alibaba-sentinel
</artifactId>
...
...
youlai-gateway/src/main/java/com/youlai/gateway/sentinel/SentinelConfiguration.java
0 → 100644
浏览文件 @
17626703
package
com.youlai.gateway.sentinel
;
import
com.alibaba.csp.sentinel.adapter.gateway.sc.callback.BlockRequestHandler
;
import
com.alibaba.csp.sentinel.adapter.gateway.sc.callback.GatewayCallbackManager
;
import
com.youlai.common.result.ResultCode
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.reactive.function.BodyInserters
;
import
org.springframework.web.reactive.function.server.ServerResponse
;
import
javax.annotation.PostConstruct
;
/**
* 自定义网关流控异常
*
* @author haoxr
* @date 2022/7/24
*/
@Configuration
public
class
SentinelConfiguration
{
@PostConstruct
private
void
initBlockHandler
()
{
BlockRequestHandler
blockRequestHandler
=
(
exchange
,
t
)
->
ServerResponse
.
status
(
HttpStatus
.
TOO_MANY_REQUESTS
)
.
contentType
(
MediaType
.
APPLICATION_JSON
)
.
body
(
BodyInserters
.
fromValue
(
ResultCode
.
FLOW_LIMITING
.
toString
())
);
GatewayCallbackManager
.
setBlockHandler
(
blockRequestHandler
);
}
}
youlai-lab/src/main/java/com/youlai/lab/sentinel/controller/SentinelController.java
浏览文件 @
17626703
...
...
@@ -9,9 +9,6 @@ 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"
)
...
...
@@ -19,11 +16,22 @@ import java.util.List;
@Slf4j
public
class
SentinelController
{
@ApiOperation
(
"【限流】获取订单列表"
)
@GetMapping
(
"/orders/_limit"
)
public
Result
listOrders
()
{
List
<
String
>
orderList
=
Arrays
.
asList
(
"订单1"
,
"订单2"
,
"订单3"
);
return
Result
.
success
(
orderList
);
@ApiOperation
(
"【普通流控】获取数据"
)
@GetMapping
(
"/flow_limiting/data"
)
public
Result
getFlowLimitingData
()
{
return
Result
.
success
(
"正常数据"
);
}
@ApiOperation
(
"【网关流控-RouteID】获取数据"
)
@GetMapping
(
"/gateway_route_flow_limiting/data"
)
public
Result
getGatewayRouteFlowLimitingData
()
{
return
Result
.
success
(
"正常数据"
);
}
@ApiOperation
(
"【网关流控-API分组】获取数据"
)
@GetMapping
(
"/gateway_api_flow_limiting/data"
)
public
Result
getGatewayApiFlowLimitingData
()
{
return
Result
.
success
(
"正常数据"
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录