如何添加全局的ProviderConfig.Parameters
OrezzerO opened this issue · 3 comments
OrezzerO commented
Your question
需求是想在注册中心中标志注册中心的记录是属于哪个 APP 的.相当于给这些记录打 tag,现在发现只能一个接口一个接口添加Parameters.是否有办法整个应用暴露的服务统一加这样子的 tag.
例子:
现状:
rest://172.20.138.128:8340/actuator/?version=1.0&accepts=100000&appName=server.sofademo.ppdaicorp.com&weight=100&language=java&pid=95603&interface=com.ppdai.framework.microservice.starter.sofa.endpoint.api.HealthCheckService&timeout=0&serialization=hessian2&protocol=rest&delay=-1&appId=10011107&dynamic=true&startTime=1552285005771&id=rpc-cfg-1&uniqueId=&rpcVer=50500
我想要的:
rest://172.20.138.128:8340/actuator/?version=1.0&accepts=100000&appName=server.sofademo.ppdaicorp.com&weight=100&language=java&pid=95603&interface=com.ppdai.framework.microservice.starter.sofa.endpoint.api.HealthCheckService&timeout=0&serialization=hessian2&protocol=rest&delay=-1&appId=10011107&dynamic=true&startTime=1552285005771&id=rpc-cfg-1&uniqueId=&rpcVer=50500&tag1=xxx&tag2=xxx
Your scenes
describe your use scenes (why need this feature)
Your advice
describe the advice or solution you'd like
Environment
- Starter version:
- JVM version (e.g.
java -version
): - OS version (e.g.
uname -a
): - Maven version:
- IDE version:
leizhiyuan commented
目前是不支持的
com.alipay.sofa.rpc.client.ProviderHelper#toUrl
主要体现在这里,如果需要支持,可以考虑将一些通用的配置,放到ServerConfig中。然后从这里构造来拿,然后拼接在url中。
OrezzerO commented
我提个 pr
OrezzerO commented
我在自己的代码里定义了一个子类来做这个事情:
public class PpdProviderConfigHelper extends ProviderConfigHelper {
@Value("${" + APP_NAME_KEY + "}")
private String appName;
@Value("${" + APP_ID_KEY + "}")
private String appId;
public ProviderConfig getProviderConfig(Contract contract, RpcBinding binding, Object target) {
ProviderConfig config = super.getProviderConfig(contract, binding, target);
config.setParameter(PROVIDER_META_INF_APP_NAME, appName);
config.setParameter(PROVIDER_META_INF_APP_ID, appId);
config.setParameter(PROVIDER_META_INF_STARTER_VERSION, Constants.STARTER_VERSION);
return config;
}
}
将它注册为 Bean:
@Bean(name = "providerConfigHelper")
public ProviderConfigHelper providerConfigHelper() {
return new PpdProviderConfigHelper();
}
注意这个 Bean 所在的 AutoConfiguation 需要在SofaBootRpcAutoConfiguration 之后执行:
@AutoConfigureAfter(value = {SofaBootRpcAutoConfiguration.class})