seninel部署
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # Sentinel Spring WebFlux Adapter
  2. Sentinel provides integration module with Spring WebFlux, so reactive web applications can also leverage Sentinel's flow control
  3. and circuit breaking to achieve reliability. 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-webflux-adapter</artifactId>
  9. <version>x.y.z</version>
  10. </dependency>
  11. ```
  12. Then you only need to inject the corresponding `SentinelWebFluxFilter` and `SentinelBlockExceptionHandler` instance
  13. in Spring configuration. For example:
  14. ```java
  15. @Configuration
  16. public class WebFluxConfig {
  17. private final List<ViewResolver> viewResolvers;
  18. private final ServerCodecConfigurer serverCodecConfigurer;
  19. public WebFluxConfig(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 SentinelBlockExceptionHandler sentinelBlockExceptionHandler() {
  27. // Register the block exception handler for Spring WebFlux.
  28. return new SentinelBlockExceptionHandler(viewResolvers, serverCodecConfigurer);
  29. }
  30. @Bean
  31. @Order(-1)
  32. public SentinelWebFluxFilter sentinelWebFluxFilter() {
  33. // Register the Sentinel WebFlux filter.
  34. return new SentinelWebFluxFilter();
  35. }
  36. }
  37. ```
  38. You can register various customized callback in `WebFluxCallbackManager`:
  39. - `setBlockHandler`: register a customized `BlockRequestHandler` to handle the blocked request. The default implementation is `DefaultBlockRequestHandler`, which returns default message like `Blocked by Sentinel: FlowException`.
  40. - `setUrlCleaner`: used for normalization of URL. The function type is `(ServerWebExchange, String) → String`, which means `(webExchange, originalUrl) → finalUrl`, if the finalUrl is `"""` or `null`, the URLs will be excluded (since Sentinel 1.7.0)..
  41. - `setRequestOriginParser`: used to resolve the origin from the HTTP request. The function type is `ServerWebExchange → String`.
  42. You can also refer to the demo: [sentinel-demo-spring-webflux](https://github.com/alibaba/Sentinel/tree/master/sentinel-demo/sentinel-demo-spring-webflux).