{"record":{"id":"72d3708a9d61cf2c","repo":"alibaba/spring-cloud-alibaba","slug":"consuldatasource-rulekey-can-not-be-empty","errorCode":null,"errorMessage":"ConsulDataSource ruleKey can not be empty","messagePattern":"ConsulDataSource ruleKey can not be empty","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-cloud-alibaba-starters/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/config/ConsulDataSourceProperties.java","lineNumber":68,"sourceCode":"\tprivate @Nullable String token;\n\n\t/**\n\t * data key in Redis.\n\t */\n\tprivate @Nullable String ruleKey;\n\n\t/**\n\t * Request of query will hang until timeout (in second) or get updated value.\n\t */\n\tprivate int waitTimeoutInSecond = 1;\n\n\t@Override\n\tpublic void preCheck(String dataSourceName) {\n\t\tif (StringUtils.isEmpty(host)) {\n\t\t\tthrow new IllegalArgumentException(\"ConsulDataSource server-host is empty\");\n\t\t}\n\t\tif (StringUtils.isEmpty(ruleKey)) {\n\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\t\"ConsulDataSource ruleKey can not be empty\");\n\t\t}\n\t}\n\n\tpublic @Nullable String getHost() {\n\t\treturn host;\n\t}\n\n\tpublic void setHost(@Nullable String host) {\n\t\tthis.host = host;\n\t}\n\n\tpublic int getPort() {\n\t\treturn port;\n\t}\n\n\tpublic void setPort(int port) {\n\t\tthis.port = port;","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/alibaba/spring-cloud-alibaba/blob/115d5901102009492e05d5ec18c3f79cad4077d0/spring-cloud-alibaba-starters/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/config/ConsulDataSourceProperties.java#L50-L86","documentation":"Thrown by ConsulDataSourceProperties.preCheck when the ruleKey field is null or empty. The ruleKey identifies the Consul KV key that holds the Sentinel rule data. This check fires after the host check passes, ensuring both required Consul-specific properties are present before datasource creation.","triggerScenarios":"Configuring a Sentinel datasource of type 'consul' with a host set but no ruleKey. The ruleKey field is @Nullable with no default, so omitting spring.cloud.sentinel.datasource.<name>.consul.ruleKey causes StringUtils.isEmpty(ruleKey) to be true.","commonSituations":"1) Developer provides consul.host but forgets ruleKey. 2) The Consul KV key name was renamed in the Consul server but not updated in application config. 3) Copy-paste error where ruleKey was left as an empty string or placeholder.","solutions":["Add spring.cloud.sentinel.datasource.<name>.consul.ruleKey=<consul-kv-key> to your configuration.","Verify the ruleKey value matches the actual key path in your Consul KV store.","Ensure the ruleKey is not an empty string (StringUtils.isEmpty catches both null and \"\")."],"exampleFix":"# before (broken — ruleKey missing)\nspring:\n  cloud:\n    sentinel:\n      datasource:\n        ds1:\n          consul:\n            host: consul.local\n\n# after (fixed)\nspring:\n  cloud:\n    sentinel:\n      datasource:\n        ds1:\n          consul:\n            host: consul.local\n            ruleKey: sentinel/sentinel-flow-rules","handlingStrategy":"validation","validationCode":"// Ensure ruleKey is set before datasource initialization\n// In YAML: spring.cloud.sentinel.datasource.<name>.consul.ruleKey must be non-empty\n// Programmatic check:\nString ruleKey = props.getConsul().getRuleKey();\nif (!StringUtils.hasText(ruleKey)) {\n    throw new IllegalArgumentException(\"ConsulDataSource ruleKey is required\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Document the Consul KV key path alongside the datasource configuration.","Verify the ruleKey exists in Consul before starting the application.","Use consistent naming conventions for Sentinel rule keys across Consul and application config."],"tags":["sentinel","consul","datasource","configuration","validation"],"backgroundTag":null,"analyzedSha":"115d5901102009492e05d5ec18c3f79cad4077d0","analyzedAt":"2026-08-14T04:47:13.900Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}