seninel部署
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # Sentinel Annotation AspectJ
  2. This extension is an AOP implementation using AspectJ for Sentinel annotations.
  3. Currently only runtime weaving 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` (refactored since 1.6.0): Fallback method when exceptions caught (including `BlockException`, but except the exceptions defined in `exceptionsToIgnore`). The fallback 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 `fallbackClass` with corresponding `Class` (Note the method in other classes must be *static*). The method signature requirement:
  9. - The return type should match the origin method;
  10. - The parameter list should match the origin method, and an additional `Throwable` parameter can be provided to get the actual exception.
  11. - `defaultFallback` (since 1.6.0): The default fallback method when exceptions caught (including `BlockException`, but except the exceptions defined in `exceptionsToIgnore`). Its intended to be a universal common fallback method. The 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 `fallbackClass` with corresponding `Class` (Note the method in other classes must be *static*). The default fallback method signature requirement:
  12. - The return type should match the origin method;
  13. - parameter list should be empty, and an additional `Throwable` parameter can be provided to get the actual exception.
  14. - `blockHandler`: Handler method that handles `BlockException` when blocked. The parameter list of the method should match original method, with the last additional parameter type `BlockException`. The return type should be same as the original method. The `blockHandler` 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*).
  15. - `exceptionsToIgnore` (since 1.6.0): List of business exception classes that should not be traced and caught in fallback.
  16. - `exceptionsToTrace` (since 1.5.1): List of business exception classes to trace and record. In most cases, using `exceptionsToIgnore` is better. If both `exceptionsToTrace` and `exceptionsToIgnore` are present, only `exceptionsToIgnore` will be activated.
  17. For example:
  18. ```java
  19. @SentinelResource(value = "abc", fallback = "doFallback")
  20. public String doSomething(long i) {
  21. return "Hello " + i;
  22. }
  23. public String doFallback(long i, Throwable t) {
  24. // Return fallback value.
  25. return "fallback";
  26. }
  27. public String defaultFallback(Throwable t) {
  28. return "default_fallback";
  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).