seninel部署
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

README.md 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # Sentinel Spring WebFlux Adapter
  2. > Note: this module requires Java 8 or later version.
  3. Sentinel provides integration module with Spring WebFlux, so reactive web applications can also leverage Sentinel's flow control
  4. and circuit breaking to achieve reliability. 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-webflux-adapter</artifactId>
  10. <version>x.y.z</version>
  11. </dependency>
  12. ```
  13. Then you only need to inject the corresponding `SentinelWebFluxFilter` and `SentinelBlockExceptionHandler` instance
  14. in Spring configuration. For example:
  15. ```java
  16. @Configuration
  17. public class WebFluxConfig {
  18. private final List<ViewResolver> viewResolvers;
  19. private final ServerCodecConfigurer serverCodecConfigurer;
  20. public WebFluxConfig(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 SentinelBlockExceptionHandler sentinelBlockExceptionHandler() {
  28. // Register the block exception handler for Spring WebFlux.
  29. return new SentinelBlockExceptionHandler(viewResolvers, serverCodecConfigurer);
  30. }
  31. @Bean
  32. @Order(-1)
  33. public SentinelWebFluxFilter sentinelWebFluxFilter() {
  34. // Register the Sentinel WebFlux filter.
  35. return new SentinelWebFluxFilter();
  36. }
  37. }
  38. ```
  39. You can register various customized callback in `WebFluxCallbackManager`:
  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`.
  41. - `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)..
  42. - `setRequestOriginParser`: used to resolve the origin from the HTTP request. The function type is `ServerWebExchange → String`.
  43. You can also refer to the demo: [sentinel-demo-spring-webflux](https://github.com/alibaba/Sentinel/tree/master/sentinel-demo/sentinel-demo-spring-webflux).