Spring cloud config + bus calls twice to the config server when the binder is created

强颜欢笑 提交于 2020-01-15 17:39:09

问题


I have created a simple project using spring-cloud-config and spring-cloud-bus. For some reason, the config client calls twice to the config server. The first time happens when the context of the bootstrap is created (what is the expected behaviour) but the second time is called when the context of the binder is created.

This is done In the class:

DefaultBinderFactory#getBinderInstance:

// If the environment is not customized and a main context is available, we
// will set the latter as parent.
// This ensures that the defaults and user-defined customizations (e.g. custom
// connection factory beans)
// are propagated to the binder context. If the environment is customized,
// then the binder context should
// not inherit any beans from the parent
boolean useApplicationContextAsParent = binderProperties.isEmpty() && this.context != null;
if (useApplicationContextAsParent) {
    springApplicationBuilder.parent(this.context);
}
if (useApplicationContextAsParent || (environment != null && binderConfiguration.isInheritEnvironment())) {
    if (environment != null) {
        StandardEnvironment binderEnvironment = new StandardEnvironment();
        binderEnvironment.merge(environment);
        springApplicationBuilder.environment(binderEnvironment);
    }
}
ConfigurableApplicationContext binderProducingContext = springApplicationBuilder
        .run(args.toArray(new String[args.size()]));

when is executed the following statement:

ConfigurableApplicationContext binderProducingContext = springApplicationBuilder
    .run(args.toArray(new String[args.size()]));

As far as I see in the code, the context of the binders are different from the context of the application. It seems that the reason of calling another time to the config server is that spring-cloud-context creates its context with an initializer PropertySourceBootstrapConfiguration loaded by the listener BootstrapApplicationListener .

So, my question is: Is this the expected behaviour? I assume that the config client should make only one request to the server at startup. If it is not correct, why is the reason for it?

The versions that I am using are the included in: spring-cloud-dependencies, version Edgware.RELEASE

Many thanks in advance!


回答1:


Yes; it's expected; the spring cloud stream binder is loaded into its own Spring Boot application (it can have different environment variables).



来源:https://stackoverflow.com/questions/48406527/spring-cloud-config-bus-calls-twice-to-the-config-server-when-the-binder-is-cr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!