Comments (4)
Hi, this makes no sense. Since you are using datasource extension, you must know where your rules is stored.
Sentinel provides an SPI extension - InitFunc
. You can implement your own InitFunc
to init the datasource. For example:
package com.test.init;
public class DataSourceInitFunc implements InitFunc {
@Override
public void init() throws Exception {
final String remoteAddress = "localhost";
final String groupId = "Sentinel:Demo";
final String dataId = "com.alibaba.csp.sentinel.demo.flow.rule";
DataSource<String, List<FlowRule>> flowRuleDataSource = new NacosDataSource<>(remoteAddress, groupId, dataId,
source -> JSON.parseObject(source, new TypeReference<List<FlowRule>>() {}));
FlowRuleManager.register2Property(flowRuleDataSource.getProperty());
}
}
Then add the class to com.alibaba.csp.sentinel.init.InitFunc
file in META-INF/services
directory of the resource directory:
com.test.init.DataSourceInitFunc
Then when you trigger a resource access, Sentinel will scan all InitFunc
and initialize the datasource automatically. You don't have to manually call it.
from sentinel.
真不知道怎么想的
from sentinel.
为什么不借鉴下dubbo的方式呢,让使用者更方便呢
from sentinel.
Hi, this makes no sense. Since you are using datasource extension, you must know where your rules is stored.
Sentinel provides an SPI extension -
InitFunc
. You can implement your ownInitFunc
to init the datasource. For example:package com.test.init; public class DataSourceInitFunc implements InitFunc { @Override public void init() throws Exception { final String remoteAddress = "localhost"; final String groupId = "Sentinel:Demo"; final String dataId = "com.alibaba.csp.sentinel.demo.flow.rule"; DataSource<String, List<FlowRule>> flowRuleDataSource = new NacosDataSource<>(remoteAddress, groupId, dataId, source -> JSON.parseObject(source, new TypeReference<List<FlowRule>>() {})); FlowRuleManager.register2Property(flowRuleDataSource.getProperty()); } }Then add the class to
com.alibaba.csp.sentinel.init.InitFunc
file inMETA-INF/services
directory of the resource directory:com.test.init.DataSourceInitFunc
Then when you trigger a resource access, Sentinel will scan all
InitFunc
and initialize the datasource automatically. You don't have to manually call it.
这种自定义InitFunc里面需要使用Spring的@autowire、@value 或者Jdk自带@resource 来获取属性会失效吧,我自己写了例子都不能成功,目前所有的demo里都是代码硬编码写死这部分动态参数
from sentinel.
Related Issues (20)
- Spi重复初始化资源问题 HOT 9
- 请问 有1.8.8或者1.9.0或者2.0.0的发布计划么 HOT 3
- Dashboard向应用服务发起Metric请求,请求失败后,无详细错误信息 HOT 1
- Improve the performance and latency for the cluster limiter
- Same name fallback/blockHandler with different parameter types cause reflect exception HOT 1
- sentinel dashboard push.,支持 nacos、apollo...实现方式
- [BUG] 多个微服务拥有相同配置,相同依赖,启动后,只有一个微服务可以在控制台看到 HOT 1
- sentinel-apache-dubbo3-adapter Specifies whether the adapter supports dubbo 3.2.x
- `defaultFallback` annotation attribute on class cause `defaultFallback` handling conflicts on methods with different return types. HOT 4
- 建议给Flow/DegradationRuleManager的规则添加append方法
- [BUG] 容器环境中tokenserver检测到的机器远多于现存应用
- [BUG] 使用nacos作为规则数据源时,获取初始化配置失败 HOT 1
- [BUG] Sentinel push Mode GatewayApiDefinitionManager.ApiDefinitionPropertyListener Deserialization fail
- Integrate Sentinel, performance torture testing with increasing number of rule configurations
- [BUG] 使用来源白名单功能时,没有设置orgin的客户端请求会立即通过,功能失效。 HOT 3
- Incorrectly described in the official document 官网文档描述有误 HOT 2
- [BUG] ParamFlowRuleManager的getRulesOfResource会有空指针异常 HOT 1
- 请问你们的集群模式的文档是给人看的吗,感觉讲一半,配置给一半?能不能给一个直接能配置出一个集群模式的文档?
- DefaultCircuitBreakerRuleManager在1.8.8已经可用了吗 HOT 1
- Persistence of gateway mode flow control rules in the Sentinel dashboard
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sentinel.