Sentinel/sentinel-adapter/sentinel-spring-cloud-gatew...
LearningGp eb3a9b099a
Bump version to 1.8.9 (#3566)
* chore: update release configuration

* Bump version to 1.8.9
2025-10-16 20:26:58 +08:00
..
src feat(adapter): new SpringCloudGateway v6 adapter for supporting the SpringCloud 2025 version (#3542) 2025-08-25 15:11:46 +08:00
README.md feat(adapter): new SpringCloudGateway v6 adapter for supporting the SpringCloud 2025 version (#3542) 2025-08-25 15:11:46 +08:00
pom.xml Bump version to 1.8.9 (#3566) 2025-10-16 20:26:58 +08:00

README.md

Sentinel Spring Cloud Gateway Adapter

Sentinel provides integration module with Spring Cloud Gateway. The integration module is based on the Sentinel Reactor Adapter.

This module is quite similar to sentinel-spring-cloud-gateway-adapter and The difference is that this module has made some adaptations for webflux 6.x.
The usage is consistent with sentinel-spring-cloud-gateway-adapter, with the difference being that the maven dependency is different.

Add the following dependency in pom.xml (if you are using Maven):

<dependency>
    <groupId>com.alibaba.csp</groupId>
    <artifactId>sentinel-spring-cloud-gateway-v6x-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
    @Order(-1)
    public GlobalFilter sentinelGatewayFilter() {
        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 customized callback in GatewayCallbackManager:

  • setBlockHandler: register a customized BlockRequestHandler to handle the blocked request. The default implementation is DefaultBlockRequestHandler, which returns default message like Blocked by Sentinel: FlowException.