You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
private URL turnRegistryUrlToConsumerUrl(URL url) {
// save any parameter in registry that will be useful to the new url.
String isDefault = url.getParameter(PREFERRED_KEY);
if (StringUtils.isNotEmpty(isDefault)) {
queryMap.put(REGISTRY_KEY + "." + PREFERRED_KEY, isDefault);
}
return URLBuilder.from(url)
.setPath(url.getServiceInterface())
.clearParameters()
.addParameters(queryMap)
.removeParameter(MONITOR_KEY)
.build();
}
dubbo2.7.5中新增了4种多注册中心选址策略,分别为
preferred
,zone
,weight
,任意可用
,但是目前
zone
,weight
是无效的,原因在于在通过registryUrl创建RegistryDirectory时,会将registryUrl中的参数清楚, 但是仅仅保留了
preferred
这个参数. 代码见org.apache.dubbo.registry.integration.RegistryDirectory#RegistryDirectory,该方法调用 turnRegistryUrlToConsumerUrl(url);将registryUrl做了转换,导致丢失了
zone
,weight
两个参数org.apache.dubbo.registry.integration.RegistryDirectory#turnRegistryUrlToConsumerUrl
该方法中只保留了PREFERRED_KEY即preferred这个参数,并设置前缀registry,但是丢失了
zone
,weight
,导致这两个选址策略无效解决方案
方案1: 在turnRegistryUrlToConsumerUrl方法中,按照和preferred同样的方式,将
zone
,weight
,添加上,**方案缺点: ** 如果后期有更多关于注册中心的参数都可能需要这么做,容易忘记编码
方案2:(建议方式) 在turnRegistryUrlToConsumerUrl方法中,保留所有的RegistryConfig参数,并设置
registry
参数**方案缺点: ** parameter参数多几个字段而已,无伤大雅
方案3: 在org.apache.dubbo.registry.integration.RegistryDirectory#RegistryDirectory类中,保存取原始的registryUrl, 即可获取RegistryConfig中的所有参数,
**方案缺点: **需要修改的类和方法比较多.
大致需要修改如下:
RegistryDirectory
添加成员变量,保存原始registryUrlorg.apache.dubbo.rpc.cluster.support.wrapper.MockClusterInvoker
添加返回directory的方法ZoneAwareClusterInvoker
中判断去除前缀The text was updated successfully, but these errors were encountered: