@ -24,10 +24,10 @@ Before we start the demo, let's learn how to connect Sentinel to a Spring Cloud
1. Define HTTP Resources
Sentinel starter defines all HTTP URLS as resources by relative paths. If you only want to add flow control for your HTTP services, you do not need to modify your code.
1. Define Custom Resources
If you want to implement flow control or degradation for a specific method, you can add an @EnableSentinel annotation to the method, as shown in the code below.
2. Define Custom Resources
If you want to implement flow control or degradation for a specific method, you can add an @SentinelResource annotation to the method, as shown in the code below.
@EnableSentinel("resource")
@SentinelResource("resource")
public String hello() {
return "Hello";
}
@ -95,11 +95,11 @@ The screenshot belows shows invoke success:
4. Configure Custom Resource Flow Rule:Click **流控规则(Flow Rule)** on the left-side navigation pane and **新增流控规则(Create Flow Rule)**. type the value() of @EnableSentinel in the **资源名(Resource Name)** field , enter **单机阈值(Threshold)** value, then click **新增(OK)**.Here we set threshold to 1 for demonstration purpose.
3. Configure Custom Resource Flow Rule:Click **流控规则(Flow Rule)** on the left-side navigation pane and **新增流控规则(Create Flow Rule)**. type the value() of @SentinelResource in the **资源名(Resource Name)** field , enter **单机阈值(Threshold)** value, then click **新增(OK)**.Here we set threshold to 1 for demonstration purpose.
@ -125,23 +125,19 @@ The screenshot belows shows invoke success:
2. 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`, add it to HandlerUtil, and set @EnableSentinel's handler(). See the code below:
public class CustomBlockHandler implements SentinelBlockHandler {
@Override
public Object handler(BlockException e) {
//todo add your logic
return null;
}
}
HandlerUtil.addHandler("myhandler", new CustomBlockHandler());
If you want to customize your flow control logic, implement interface `SentinelExceptionHandler`, set @SentinelResource's blockHandler() and blockHandlerClass(). See the code below:
[Dubbo](http://dubbo.apache.org/) is a high-performance, java based open source RPC framework.
Sentinel provide a module named [sentinel-dubbo-adapter](https://github.com/alibaba/Sentinel/tree/master/sentinel-adapter/sentinel-dubbo-adapter)to support dubbo。sentinel-starter integrates this feature by default.
For example, a service named FooService, see the code below: