seninel部署
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

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