seninel部署
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

README.md 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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). The fallback method should be located in the same class with original method. The signature of the fallback method should match the original method (parameter types and return type).
  9. - `blockHandler`: Handler method that handles `BlockException` when blocked. The signature should match original method, with the last additional parameter type `BlockException`. The block handler method should be located in the same class with original method by default. If you want to use method in other classes, you can set the `blockHandlerClass` with corresponding `Class` (Note the method in other classes must be *static*).
  10. For example:
  11. ```java
  12. @SentinelResource(value = "abc", fallback = "doFallback", blockHandler = "handleException")
  13. public String doSomething(long i) {
  14. return "Hello " + i;
  15. }
  16. public String doFallback(long i) {
  17. // Return fallback value.
  18. return "Oops, degraded";
  19. }
  20. public String handleException(long i, BlockException ex) {
  21. // Handle the block exception here.
  22. return null;
  23. }
  24. ```
  25. ## Configuration
  26. ### AspectJ
  27. If you are using AspectJ directly, you can add the Sentinel annotation aspect to
  28. your `aop.xml`:
  29. ```xml
  30. <aspects>
  31. <aspect name="com.alibaba.csp.sentinel.annotation.aspectj.SentinelResourceAspect"/>
  32. </aspects>
  33. ```
  34. ### Spring AOP
  35. If you are using Spring AOP, you should add a configuration to register the aspect
  36. as a Spring bean:
  37. ```java
  38. @Configuration
  39. public class SentinelAspectConfiguration {
  40. @Bean
  41. public SentinelResourceAspect sentinelResourceAspect() {
  42. return new SentinelResourceAspect();
  43. }
  44. }
  45. ```
  46. 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).