seninel部署
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # Sentinel Parameter Flow Control
  2. This component provides functionality of flow control by frequent ("hot spot") parameters.
  3. ## Usage
  4. To use Sentinel Parameter Flow Control, you need to add the following dependency to `pom.xml`:
  5. ```xml
  6. <dependency>
  7. <groupId>com.alibaba.csp</groupId>
  8. <artifactId>sentinel-parameter-flow-control</artifactId>
  9. <version>x.y.z</version>
  10. </dependency>
  11. ```
  12. First you need to pass parameters with the following `SphU.entry` overloaded methods:
  13. ```java
  14. public static Entry entry(String name, EntryType type, int count, Object... args) throws BlockException
  15. public static Entry entry(Method method, EntryType type, int count, Object... args) throws BlockException
  16. ```
  17. For example, if there are two parameters to provide, you can:
  18. ```java
  19. // paramA in index 0, paramB in index 1.
  20. SphU.entry(resourceName, EntryType.IN, 1, paramA, paramB);
  21. ```
  22. Then you can configure parameter flow control rules via `loadRules` method in `ParamFlowRuleManager`:
  23. ```java
  24. // QPS mode, threshold is 5 for every frequent "hot spot" parameter in index 0 (the first arg).
  25. ParamFlowRule rule = new ParamFlowRule(RESOURCE_KEY)
  26. .setParamIdx(0)
  27. .setCount(5);
  28. // We can set threshold count for specific parameter value individually.
  29. // Here we add an exception item. That means: QPS threshold of entries with parameter `PARAM_B` (type: int)
  30. // in index 0 will be 10, rather than the global threshold (5).
  31. ParamFlowItem item = new ParamFlowItem().setObject(String.valueOf(PARAM_B))
  32. .setClassType(int.class.getName())
  33. .setCount(10);
  34. rule.setParamFlowItemList(Collections.singletonList(item));
  35. ParamFlowRuleManager.loadRules(Collections.singletonList(rule));
  36. ```
  37. The description for fields of `ParamFlowRule`:
  38. | Field | Description | Default |
  39. | :----: | :----| :----|
  40. | resource| resource name (**required**) ||
  41. | count | flow control threshold (**required**) ||
  42. | grade | flow control mode (only QPS mode is supported) | QPS mode |
  43. | paramIdx | the index of provided parameter in `SphU.entry(xxx, args)` (**required**) ||
  44. | paramFlowItemList | the exception items of parameter; you can set threshold to a specific parameter value ||
  45. Now the parameter flow control rules will take effect.