Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

registry和protocol相关配置非常混乱,很多情况下都是错误的 #6967

Closed
wikiwikiwiki opened this issue Nov 30, 2020 · 0 comments · Fixed by #6968
Closed

registry和protocol相关配置非常混乱,很多情况下都是错误的 #6967

wikiwikiwiki opened this issue Nov 30, 2020 · 0 comments · Fixed by #6968
Labels
type/proposal Everything you want Dubbo have

Comments

@wikiwikiwiki
Copy link

wikiwikiwiki commented Nov 30, 2020

Dubbo version: 2.7.6

dubbo 2.7里面protocol相关的配置的有protocols和protocolIds,不同级别的配置也有多个比如ServiceConfig和ProviderConfig,而现在dubbo里没有能很好处理相关的优先级,导致配置的生效非常混乱,很多情况下都是错的。

这里以protocol来做例子,registry相关的配置有registrys和registryIds,也是同理。
合理的优先级应该是 ServiceConfig.protocolIds -> ServiceConfig.protocols -> ProviderConfig.protocolIds -> ProviderConfig.protocols。

ServiceConfigBase的completeCompoundConfigs方法是ServiceConfig.export()最先调用的方法,看看它的代码:

    public void completeCompoundConfigs() {
        super.completeCompoundConfigs(provider);
        if (provider != null) {
            if (protocols == null) {
                setProtocols(provider.getProtocols());
            }
            if (configCenter == null) {
                setConfigCenter(provider.getConfigCenter());
            }
            if (StringUtils.isEmpty(registryIds)) {
                setRegistryIds(provider.getRegistryIds());
            }
            if (StringUtils.isEmpty(protocolIds)) {
                setProtocolIds(provider.getProtocolIds());
            }
        }
    }

可以看到,如果在ServiceConfig里设置了protocols p1,ProviderConfig设置了protocolIds p2,那么最终ServiceConfig的protocols属性为p1,protocolIds属性为p2,通过后面的convertProtocolIdsToProtocols方法处理后,生效的会是p2,而不是p1。

在使用过程中,xml方式定义的dubbo配置会调用setProtocolIds,而api方式定义的dubbo我们往往会使用setProtocols这样的方法,如果两种方式混合使用,更加容易出错(比如中间价在jar包里使用api方式,业务代码在xml里定义)。

类似的处理代码还散落在多个地方,导致protocol和registry的配置非常混乱而容易出错。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/proposal Everything you want Dubbo have
Projects
None yet
2 participants