Sentinel Parameter Flow Control provides functionality of flow control by frequent (hot spot) parameters.
—
Core functionality for defining, loading, and managing parameter flow control rules. The ParamFlowRuleManager provides centralized rule configuration with support for dynamic updates and rule validation.
Loads parameter flow rules, replacing any previously configured rules. This is the primary method for configuring parameter flow control.
/**
* Load parameter flow rules. Former rules will be replaced.
* @param rules new rules to load
*/
public static void loadRules(List<ParamFlowRule> rules);Usage Example:
import com.alibaba.csp.sentinel.slots.block.flow.param.*;
import java.util.Arrays;
// Create multiple rules
ParamFlowRule userRule = new ParamFlowRule("userService")
.setParamIdx(0)
.setCount(10)
.setGrade(RuleConstant.FLOW_GRADE_QPS);
ParamFlowRule productRule = new ParamFlowRule("productService")
.setParamIdx(1)
.setCount(20)
.setGrade(RuleConstant.FLOW_GRADE_QPS);
// Load all rules at once
ParamFlowRuleManager.loadRules(Arrays.asList(userRule, productRule));Registers a property listener for dynamic rule updates from external configuration sources.
/**
* Listen to the SentinelProperty for ParamFlowRules. The property is the source of ParamFlowRules.
* Parameter flow rules can also be set by loadRules(List) directly.
* @param property the property to listen
*/
public static void register2Property(SentinelProperty<List<ParamFlowRule>> property);Usage Example:
import com.alibaba.csp.sentinel.property.DynamicSentinelProperty;
import com.alibaba.csp.sentinel.property.SentinelProperty;
// Create a dynamic property for rule updates
SentinelProperty<List<ParamFlowRule>> ruleProperty = new DynamicSentinelProperty<>();
// Register the property with the rule manager
ParamFlowRuleManager.register2Property(ruleProperty);
// Rules can now be updated through the property
ruleProperty.updateValue(newRules);Retrieves all parameter flow rules configured for a specific resource.
/**
* Get rules for a specific resource
* @param resourceName the resource name
* @return list of rules for the resource, never null
*/
public static List<ParamFlowRule> getRulesOfResource(String resourceName);Usage Example:
// Get all rules for a specific resource
List<ParamFlowRule> userServiceRules = ParamFlowRuleManager.getRulesOfResource("userService");
// Check if any rules exist
if (!userServiceRules.isEmpty()) {
System.out.println("Found " + userServiceRules.size() + " rules for userService");
for (ParamFlowRule rule : userServiceRules) {
System.out.println("Parameter index: " + rule.getParamIdx() + ", Count: " + rule.getCount());
}
}Checks whether a resource has any configured parameter flow rules.
/**
* Check if a resource has any parameter flow rules configured
* @param resourceName the resource name
* @return true if rules exist, false otherwise
*/
public static boolean hasRules(String resourceName);Usage Example:
// Check if resource has rules before processing
if (ParamFlowRuleManager.hasRules("userService")) {
// Parameter flow control is enabled for this resource
System.out.println("Parameter flow control active for userService");
} else {
System.out.println("No parameter flow rules configured for userService");
}Retrieves a copy of all currently loaded parameter flow rules.
/**
* Get a copy of all the rules
* @return a new copy of all the rules
*/
public static List<ParamFlowRule> getRules();Usage Example:
// Get all configured rules
List<ParamFlowRule> allRules = ParamFlowRuleManager.getRules();
// Display rule summary
System.out.println("Total rules configured: " + allRules.size());
for (ParamFlowRule rule : allRules) {
System.out.println("Resource: " + rule.getResource() +
", Param Index: " + rule.getParamIdx() +
", Count: " + rule.getCount());
}The rule manager automatically validates rules during loading:
Invalid rules are logged and ignored during the loading process.
All ParamFlowRuleManager methods are thread-safe and can be called concurrently from multiple threads. Rule updates are atomic and consistent across all threads.
Install with Tessl CLI
npx tessl i tessl/maven-sentinel-parameter-flow-control