mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
update docs
This commit is contained in:
parent
5738ae700e
commit
89178bc913
@ -122,28 +122,30 @@
|
|||||||
|
|
||||||
## 自定义限流处理逻辑
|
## 自定义限流处理逻辑
|
||||||
|
|
||||||
1. URL 限流触发后默认处理逻辑是,直接返回 "Blocked by Sentinel (flow limiting)"。
|
* 默认限流异常处理
|
||||||
|
|
||||||
|
URL 限流触发后默认处理逻辑是,直接返回 "Blocked by Sentinel (flow limiting)"。
|
||||||
如果需要自定义处理逻辑,实现的方式如下:
|
如果需要自定义处理逻辑,实现的方式如下:
|
||||||
|
|
||||||
```java
|
```java
|
||||||
public class CustomUrlBlockHandler implements UrlBlockHandler {
|
public class CustomUrlBlockHandler implements UrlBlockHandler {
|
||||||
@Override
|
@Override
|
||||||
public void blocked(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException {
|
public void blocked(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException {
|
||||||
// todo add your logic
|
// todo add your logic
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WebCallbackManager.setUrlBlockHandler(new CustomUrlBlockHandler());
|
WebCallbackManager.setUrlBlockHandler(new CustomUrlBlockHandler());
|
||||||
```
|
```
|
||||||
|
|
||||||
2. 自定义限流触发后,默认的处理逻辑是抛出异常。
|
* 使用 `@SentinelResource` 注解下的限流异常处理
|
||||||
|
|
||||||
如果需要自定义处理逻辑,填写 `@SentinelResource` 注解的 `blockHandler` 属性(针对所有类型的 `BlockException`,需自行判断)或 `fallback` 属性(针对熔断降级异常),注意**对应方法的签名和位置有限制**,详情见 [Sentinel 注解支持文档](https://github.com/alibaba/Sentinel/wiki/%E6%B3%A8%E8%A7%A3%E6%94%AF%E6%8C%81#sentinelresource-%E6%B3%A8%E8%A7%A3)。示例实现如下:
|
如果需要自定义处理逻辑,填写 `@SentinelResource` 注解的 `blockHandler` 属性(针对所有类型的 `BlockException`,需自行判断)或 `fallback` 属性(针对熔断降级异常),注意**对应方法的签名和位置有限制**,详情见 [Sentinel 注解支持文档](https://github.com/alibaba/Sentinel/wiki/%E6%B3%A8%E8%A7%A3%E6%94%AF%E6%8C%81#sentinelresource-%E6%B3%A8%E8%A7%A3)。示例实现如下:
|
||||||
|
|
||||||
```java
|
```java
|
||||||
public class TestService {
|
public class TestService {
|
||||||
|
|
||||||
// blockHandler 是位于 ExceptionUtil 类下的 handleException 静态方法,需符合对应的类型限制.
|
// blockHandler 是位于 ExceptionUtil 类下的 handleException 静态方法,需符合对应的类型限制.
|
||||||
@SentinelResource(value = "test", blockHandler = "handleException", blockHandlerClass = {ExceptionUtil.class})
|
@SentinelResource(value = "test", blockHandler = "handleException", blockHandlerClass = {ExceptionUtil.class})
|
||||||
public void test() {
|
public void test() {
|
||||||
System.out.println("Test");
|
System.out.println("Test");
|
||||||
@ -172,7 +174,7 @@ public final class ExceptionUtil {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
一个简单的示例可以见 [sentinel-demo-annotation-spring-aop](https://github.com/alibaba/Sentinel/tree/master/sentinel-demo/sentinel-demo-annotation-spring-aop)。
|
一个简单的 `@SentinelResource` 示例可以见 [sentinel-demo-annotation-spring-aop](https://github.com/alibaba/Sentinel/tree/master/sentinel-demo/sentinel-demo-annotation-spring-aop)。
|
||||||
|
|
||||||
## Endpoint 信息查看
|
## Endpoint 信息查看
|
||||||
|
|
||||||
|
@ -108,7 +108,9 @@ The screenshot belows shows invoke success:
|
|||||||
|
|
||||||
## Customize Flow Control Logic
|
## Customize Flow Control Logic
|
||||||
|
|
||||||
1. When a URL resource is blocked by Sentinel, the default logic is return HTTP response "Blocked by Sentinel (flow limiting)".
|
* Flow control exception handle by default
|
||||||
|
|
||||||
|
When a URL resource is blocked by Sentinel, the default logic is return HTTP response "Blocked by Sentinel (flow limiting)".
|
||||||
|
|
||||||
If you want to customize your flow control logic, see the code below:
|
If you want to customize your flow control logic, see the code below:
|
||||||
|
|
||||||
@ -123,7 +125,9 @@ The screenshot belows shows invoke success:
|
|||||||
WebCallbackManager.setUrlBlockHandler(new CustomUrlBlockHandler());
|
WebCallbackManager.setUrlBlockHandler(new CustomUrlBlockHandler());
|
||||||
|
|
||||||
|
|
||||||
2. When a custom resource is blocked by Sentinel, the default logic is throw BlockException.
|
* Flow control exception handle by using `@SentinelResource`
|
||||||
|
|
||||||
|
When a custom resource is blocked by Sentinel, the default logic is throw BlockException.
|
||||||
|
|
||||||
If you want to customize your flow control logic, implement interface `SentinelExceptionHandler`, set @SentinelResource's blockHandler() and blockHandlerClass(). See the code below:
|
If you want to customize your flow control logic, implement interface `SentinelExceptionHandler`, set @SentinelResource's blockHandler() and blockHandlerClass(). See the code below:
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user