seninel部署
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # Sentinel Annotation AspectJ
  2. This extension is an AOP implementation using AspectJ for Sentinel annotations.
  3. Currently only runtime waving is supported.
  4. ## Annotation
  5. The `@SentinelResource` annotation indicates a resource definition, including:
  6. - `value`: Resource name, required (cannot be empty)
  7. - `entryType`: Resource entry type (inbound or outbound), `EntryType.OUT` by default
  8. - `fallback`: Fallback method when degraded (optional).
  9. The fallback method should be located in the same class with original method.
  10. The signature of the fallback method should match the original method (parameter types and return type).
  11. - `blockHandler`: Handler method that handles `BlockException` when blocked.
  12. The signature should match original method, with the last additional parameter type `BlockException`.
  13. The block handler method should be located in the same class with original method by default.
  14. If you want to use method in other classes, you can set the `blockHandlerClass` with corresponding `Class`
  15. (Note the method in other classes must be *static*).
  16. For example:
  17. ```java
  18. @SentinelResource(value = "abc", fallback = "doFallback", blockHandler = "handleException")
  19. public String doSomething(long i) {
  20. return "Hello " + i;
  21. }
  22. public String doFallback(long i) {
  23. // Return fallback value.
  24. return "Oops, degraded";
  25. }
  26. public String handleException(long i, BlockException ex) {
  27. // Handle the block exception here.
  28. return null;
  29. }
  30. ```
  31. ## Configuration
  32. ### AspectJ
  33. If you are using AspectJ directly, you can add the Sentinel annotation aspect to
  34. your `aop.xml`:
  35. ```xml
  36. <aspects>
  37. <aspect name="com.alibaba.csp.sentinel.annotation.aspectj.SentinelResourceAspect"/>
  38. </aspects>
  39. ```
  40. ### Spring AOP
  41. If you are using Spring AOP, you should add a configuration to register the aspect
  42. as a Spring bean:
  43. ```java
  44. @Configuration
  45. public class SentinelAspectConfiguration {
  46. @Bean
  47. public SentinelResourceAspect sentinelResourceAspect() {
  48. return new SentinelResourceAspect();
  49. }
  50. }
  51. ```
  52. An example for using Sentinel Annotation AspectJ with Spring Boot can be found [here](https://github.com/alibaba/Sentinel/tree/master/sentinel-demo/sentinel-demo-annotation-spring-aop).