-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
feat: Connect spring cloud properties refresh #4303
feat: Connect spring cloud properties refresh #4303
Conversation
Codecov Report
@@ Coverage Diff @@
## master #4303 +/- ##
=========================================
Coverage 53.37% 53.37%
+ Complexity 2684 2681 -3
=========================================
Files 490 490
Lines 15252 15252
Branches 1586 1586
=========================================
Hits 8141 8141
- Misses 6552 6555 +3
+ Partials 559 556 -3
Continue to review full report at Codecov.
|
ConfigurableListableBeanFactory beanFactory, | ||
ApplicationContext applicationContext) { | ||
super(environment, beanFactory); | ||
this.applicationContext = applicationContext; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to retrieve the RefreshScope bean here and cache it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to retrieve the RefreshScope bean here and cache it?
fixed
private void adapterSpringCloud(ConfigChangeEvent changeEvent) { | ||
RefreshScope refreshScope = applicationContext.getBean(RefreshScope.class); | ||
if (refreshScope != null) { | ||
refreshScope.refreshAll(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refreshAll
is kind of a dangerous operation, it could cause unexpected behaviors, e.g. eureka service up and down. So I think we need to allow users to customize the change listener behaviors.
There was a config apollo.autoUpdateInjectedSpringProperties
to control whether AutoUpdateConfigChangeListener is enabled or not. I think we need to also have two configs to control whether refreshScope.refreshAll
and applicationContext.publishEvent
are enabled respectively.
With that said, I would suggest we refactor the change listener logic instead of adding a new SpringCloudConfigPropertySourceProcessor
- Define a Service Provider Interface, e.g. SpringAutoUpdateConfigChangeListener
- Implement different implementations: AutoUpdateConfigChangeListener(the current one), SpringCloudRefreshScopeConfigChangeListener, SpringCloudEnviromentChangeEventConfigChangeListener
- Use ServiceBootstrap#loadAllOrdered method to load all the implementations in PropertySourcesProcessor#initializeAutoUpdatePropertiesFeature
- Write a CompositeConfigChagneListener to trigger each of the change listener
- In the onChange method, each listener will first check whether itself is enabled, then will do the actual work if enabled.
The benefit of this architecture is it's easy to add more customized config change listeners in the future.
If you like this idea, I think I could contribute to the refactoring part.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, Sounds good, l prefer it. Maybe we can base this code and create another PR to do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I submitted #4305 to enable the spi mechanism, please help to take a look.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I submitted #4305 to enable the spi mechanism, please help to take a look.
Got it.
apollo-client/pom.xml
Outdated
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-context</artifactId> | ||
<scope>provided</scope> | ||
</dependency> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think optional
is more appropriate and it's better to move it up with the spring-boot dependencies.
<dependency> | |
<groupId>org.springframework.cloud</groupId> | |
<artifactId>spring-cloud-context</artifactId> | |
<scope>provided</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.springframework.cloud</groupId> | |
<artifactId>spring-cloud-context</artifactId> | |
<optional>true</optional> | |
</dependency> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
optional
is more appropriate and it's better to move it up with the spring-boot dependencies.
fixed
Do we need to create a new maven module like i.e let user choose client base on their runtime. And the code will be more clear? i.e we know this feature only enable in spring cloud |
@Anilople This is a good idea. I will do the refactoring mentioned in this thread in apollo-client module and I think the spring-cloud-starter-apollo-client module could then enable more spring cloud features based on the spi mechanism? |
List<ConfigPropertySource> configPropertySources = configPropertySourceFactory.getAllConfigPropertySources(); | ||
for (ConfigPropertySource configPropertySource : configPropertySources) { | ||
configPropertySource.addChangeListener(autoUpdateConfigChangeListener); | ||
configPropertySource.addChangeListener(configChangeListener(this.environment, beanFactory)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we create a new config change listener for every configPropertySource?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we create a new config change listener for every configPropertySource?
fixed
private void adapterSpringCloud(ConfigChangeEvent changeEvent) { | ||
RefreshScope refreshScope = applicationContext.getBean(RefreshScope.class); | ||
if (refreshScope != null) { | ||
refreshScope.refreshAll(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I submitted #4305 to enable the spi mechanism, please help to take a look.
Spi sounds a good idea. |
….com/gy09535/apollo into feature/support-spring-cloud-refresh
This pull request has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in 14 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions! |
@gy09535 as apollo 2.0.0 is released, we may continue this pr to create a separate spring cloud client repository? |
|
I'm thinking we could create a new repo under apolloconfig to host spring-cloud-apollo, how do you think? |
What's the purpose of this PR
通过整合 Spring Cloud 来完成对如下内容更新:
参考:
https://github.com/spring-cloud/spring-cloud-commons/blob/087b94a905c5428c89e4db22a6a284999d5d0a7d/spring-cloud-context/src/main/java/org/springframework/cloud/logging/LoggingRebinder.java
https://github.com/spring-cloud/spring-cloud-commons/blob/14efdc71c70c10347c55ccdee4e63c01424fa038/spring-cloud-context/src/main/java/org/springframework/cloud/context/properties/ConfigurationPropertiesRebinder.java
https://github.com/spring-cloud/spring-cloud-commons/blob/5d0915b8ad45719078b599234ff236e342c216dc/spring-cloud-context/src/main/java/org/springframework/cloud/autoconfigure/RefreshAutoConfiguration.java
Which issue(s) this PR fixes:
Fixes #4293
Follow this checklist to help us incorporate your contribution quickly and easily:
mvn clean test
to make sure this pull request doesn't break anything.CHANGES
log.