-
Notifications
You must be signed in to change notification settings - Fork 8.2k
API Gateway Flow Control
Eric Zhao edited this page Aug 15, 2019
·
6 revisions
Sentinel supports flow control for API gateways like Spring Cloud Gateway and Zuul 1.x.
Sentinel provides the integration module with Spring Cloud Gateway. The integration module is based on the Sentinel Reactor Adapter.
Add the following dependency in pom.xml (if you are using Maven):
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-spring-cloud-gateway-adapter</artifactId>
<version>x.y.z</version>
</dependency>Then you only need to inject the corresponding SentinelGatewayFilter and SentinelGatewayBlockExceptionHandler instance
in Spring configuration. For example:
@Configuration
public class GatewayConfiguration {
private final List<ViewResolver> viewResolvers;
private final ServerCodecConfigurer serverCodecConfigurer;
public GatewayConfiguration(ObjectProvider<List<ViewResolver>> viewResolversProvider,
ServerCodecConfigurer serverCodecConfigurer) {
this.viewResolvers = viewResolversProvider.getIfAvailable(Collections::emptyList);
this.serverCodecConfigurer = serverCodecConfigurer;
}
@Bean
@Order(-1)
public SentinelGatewayBlockExceptionHandler sentinelGatewayBlockExceptionHandler() {
// Register the block exception handler for Spring Cloud Gateway.
return new SentinelGatewayBlockExceptionHandler(viewResolvers, serverCodecConfigurer);
}
@Bean
public GlobalFilter sentinelGatewayFilter() {
// By default the order is HIGHEST_PRECEDENCE
return new SentinelGatewayFilter();
}
}The gateway adapter will regard all routeId (defined in Spring properties) and all customized API definitions
(defined in GatewayApiDefinitionManager of sentinel-api-gateway-adapter-common module) as resources.
You can register various kinds of customized callback in GatewayCallbackManager:
-
setBlockHandler: register a customizedBlockRequestHandlerto handle the blocked request. The default implementation isDefaultBlockRequestHandler, which returns default message likeBlocked by Sentinel: FlowException.
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-zuul-adapter</artifactId>
<version>x.y.z</version>
</dependency>-
文档
-
Documents
- Read Me
- Introduction
- How to Use
- How it Works
- Flow Control
- Parameter Flow Control
- Cluster Flow Control
- API Gateway Flow Control
- Circuit Breaking
- Adaptive System Protection
- Metrics
- General Configuration
- Dynamic Rule Configuration
- Dashboard
- Integrations with open-source frameworks
- Contribution Guideline