seninel部署
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

README.md 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # Sentinel Spring Cloud Gateway Adapter
  2. > Note: this module requires Java 8 or later version.
  3. Sentinel provides integration module with Spring Cloud Gateway.
  4. The integration module is based on the Sentinel Reactor Adapter.
  5. Add the following dependency in `pom.xml` (if you are using Maven):
  6. ```xml
  7. <dependency>
  8. <groupId>com.alibaba.csp</groupId>
  9. <artifactId>sentinel-spring-cloud-gateway-adapter</artifactId>
  10. <version>x.y.z</version>
  11. </dependency>
  12. ```
  13. Then you only need to inject the corresponding `SentinelGatewayFilter` and `SentinelGatewayBlockExceptionHandler` instance
  14. in Spring configuration. For example:
  15. ```java
  16. @Configuration
  17. public class GatewayConfiguration {
  18. private final List<ViewResolver> viewResolvers;
  19. private final ServerCodecConfigurer serverCodecConfigurer;
  20. public GatewayConfiguration(ObjectProvider<List<ViewResolver>> viewResolversProvider,
  21. ServerCodecConfigurer serverCodecConfigurer) {
  22. this.viewResolvers = viewResolversProvider.getIfAvailable(Collections::emptyList);
  23. this.serverCodecConfigurer = serverCodecConfigurer;
  24. }
  25. @Bean
  26. @Order(-1)
  27. public SentinelGatewayBlockExceptionHandler sentinelGatewayBlockExceptionHandler() {
  28. // Register the block exception handler for Spring Cloud Gateway.
  29. return new SentinelGatewayBlockExceptionHandler(viewResolvers, serverCodecConfigurer);
  30. }
  31. @Bean
  32. @Order(-1)
  33. public GlobalFilter sentinelGatewayFilter() {
  34. return new SentinelGatewayFilter();
  35. }
  36. }
  37. ```
  38. The gateway adapter will regard all `routeId` (defined in Spring properties) and all customized API definitions
  39. (defined in `GatewayApiDefinitionManager` of `sentinel-api-gateway-adapter-common` module) as resources.
  40. You can register various customized callback in `GatewayCallbackManager`:
  41. - `setBlockHandler`: register a customized `BlockRequestHandler` to handle the blocked request. The default implementation is `DefaultBlockRequestHandler`, which returns default message like `Blocked by Sentinel: FlowException`.