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.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # Sentinel Web Servlet Filter
  2. Sentinel provides Servlet filter integration to enable flow control for web requests. Add the following dependency in `pom.xml` (if you are using Maven):
  3. ```xml
  4. <dependency>
  5. <groupId>com.alibaba.csp</groupId>
  6. <artifactId>sentinel-web-servlet</artifactId>
  7. <version>x.y.z</version>
  8. </dependency>
  9. ```
  10. To use the filter, you can simply configure your `web.xml` with:
  11. ```xml
  12. <filter>
  13. <filter-name>SentinelCommonFilter</filter-name>
  14. <filter-class>com.alibaba.csp.sentinel.adapter.servlet.CommonFilter</filter-class>
  15. </filter>
  16. <filter-mapping>
  17. <filter-name>SentinelCommonFilter</filter-name>
  18. <url-pattern>/*</url-pattern>
  19. </filter-mapping>
  20. ```
  21. For Spring web applications you can configure with Spring bean:
  22. ```java
  23. @Configuration
  24. public class FilterConfig {
  25. @Bean
  26. public FilterRegistrationBean sentinelFilterRegistration() {
  27. FilterRegistrationBean<Filter> registration = new FilterRegistrationBean<>();
  28. registration.setFilter(new CommonFilter());
  29. registration.addUrlPatterns("/*");
  30. registration.setName("sentinelFilter");
  31. registration.setOrder(1);
  32. return registration;
  33. }
  34. }
  35. ```
  36. When a request is blocked, Sentinel servlet filter will give a default page indicating the request blocked.
  37. If customized block page is set (via `WebServletConfig.setBlockPage(blockPage)` method),
  38. the filter will redirect the request to provided URL. You can also implement your own
  39. block handler (the `UrlBlockHandler` interface) and register to `WebCallbackManager`.
  40. The `UrlCleaner` interface is designed for clean and unify the URL resource.
  41. For REST APIs, you have to clean the URL resource (e.g. `/foo/1` and `/foo/2` -> `/foo/:id`), or
  42. the amount of context and resources will exceed the threshold.
  43. `RequestOriginParser` interface is useful for extracting request origin (e.g. IP or appName from HTTP Header)
  44. from HTTP request. You can implement your own `RequestOriginParser` and register to `WebCallbackManager`.