seninel部署
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. - `exceptionsToTrace`: List of business exception classes to trace and record (since 1.5.1).
  11. For example:
  12. ```java
  13. @SentinelResource(value = "abc", fallback = "doFallback", blockHandler = "handleException")
  14. public String doSomething(long i) {
  15. return "Hello " + i;
  16. }
  17. public String doFallback(long i) {
  18. // Return fallback value.
  19. return "Oops, degraded";
  20. }
  21. public String handleException(long i, BlockException ex) {
  22. // Handle the block exception here.
  23. return null;
  24. }
  25. ```
  26. ## Configuration
  27. ### AspectJ
  28. If you are using AspectJ directly, you can add the Sentinel annotation aspect to
  29. your `aop.xml`:
  30. ```xml
  31. <aspects>
  32. <aspect name="com.alibaba.csp.sentinel.annotation.aspectj.SentinelResourceAspect"/>
  33. </aspects>
  34. ```
  35. ### Spring AOP
  36. If you are using Spring AOP, you should add a configuration to register the aspect
  37. as a Spring bean:
  38. ```java
  39. @Configuration
  40. public class SentinelAspectConfiguration {
  41. @Bean
  42. public SentinelResourceAspect sentinelResourceAspect() {
  43. return new SentinelResourceAspect();
  44. }
  45. }
  46. ```
  47. 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).