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

feature: add Spring Boot 2.4 config data loader support #3754

Merged
merged 73 commits into from
Jun 26, 2021

Conversation

vdiskg
Copy link
Contributor

@vdiskg vdiskg commented Jun 11, 2021

What's the purpose of this PR

1. add Spring Boot 2.4 config data loader support

2. make apollo client system property names valid and add warn to the deprecated property names

see the unit test
ApolloClientSystemPropertyInitializerTest#testSystemPropertyNames

see the warn
com.ctrip.framework.apollo.util.ConfigUtil#getDeprecatedCustomizedCacheRoot
com.ctrip.framework.foundation.internals.provider.DefaultApplicationProvider#initDeprecatedAccessKey
com.ctrip.framework.apollo.internals.ConfigServiceLocator#getDeprecatedCustomizedConfigService

2.1 property names changed:

apollo.cacheDir -> apollo.cache-dir
apollo.accesskey.secret -> apollo.access-key.secret
apollo.configService -> apollo.config-service

2.2 environment variables names changed:

APOLLO_CACHEDIR -> APOLLO_CACHE_DIR
APOLLO_ACCESSKEY_SECRET -> APOLLO_ACCESS_KEY_SECRET
APOLLO_CONFIGSERVICE -> APOLLO_CONFIG_SERVICE

3. add webClient extension for apollo client

4. add extension messaging type long_polling, websocket

the default value is apollo.client.extension.messaging-type=long_polling and the websocket is just a empty Implementation
as a placeholder, and will complete in a future version

Which issue(s) this PR fixes:

Fixes #3697

Instruction

1. Basic Functions

1.1 add the dependency

        <dependency>
            <groupId>com.ctrip.framework.apollo</groupId>
            <artifactId>apollo-client-config-data</artifactId>
        </dependency>

1.2 configure the app.id, env, apollo.meta same way as before

1.3 configure spring.config.import on application.properties or application.yml

using default namespace application

# old way
# apollo.bootstrap.enabled=true
# not configure apollo.bootstrap.namespaces
# new way
spring.config.import=apollo://

or

# old way
# apollo.bootstrap.enabled=true
# apollo.bootstrap.namespaces=application
# new way
spring.config.import=apollo://application

using custom namespace

# old way
# apollo.bootstrap.enabled=true
# apollo.bootstrap.namespaces=your-namespace
# new way
spring.config.import=apollo://your-namespace

using multi namespaces
note: please put upside down of your multi namespaces.

# old way
# apollo.bootstrap.enabled=true
# apollo.bootstrap.namespaces=namespace1,namespace2,namespace3
# new way
spring.config.import=apollo://namespace3, apollo://namespace2, apollo://namespace1

2. webClient with spi

2.1 webClient dependency note

webClient can based on reactor netty httpclient, jetty reactive httpclient or apache httpclient5. the necessary dependency are as below

2.1.1 reactor netty httpclient
        <!-- webclient -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webflux</artifactId>
        </dependency>
        <!-- reactor netty httpclient -->
        <dependency>
            <groupId>io.projectreactor.netty</groupId>
            <artifactId>reactor-netty-http</artifactId>
        </dependency>
2.1.2 jetty reactive httpclient
        <!-- webclient -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webflux</artifactId>
        </dependency>
        <!-- jetty reactive httpclient -->
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-reactive-httpclient</artifactId>
        </dependency>
2.1.3 apache httpclient5
        <!-- webclient -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webflux</artifactId>
        </dependency>
        <!-- apache httpclient5 -->
        <dependency>
            <groupId>org.apache.httpcomponents.client5</groupId>
            <artifactId>httpclient5</artifactId>
            <version>5.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents.core5</groupId>
            <artifactId>httpcore5-reactive</artifactId>
            <version>5.1</version>
        </dependency>

2.2 add the dependency

        <dependency>
            <groupId>com.ctrip.framework.apollo</groupId>
            <artifactId>apollo-client-config-data</artifactId>
        </dependency>
        <!-- webclient -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webflux</artifactId>
        </dependency>
        <!-- reactor netty httpclient as an example here, both jetty reactive httpclient or apache httpclient5 are ok -->
        <dependency>
            <groupId>io.projectreactor.netty</groupId>
            <artifactId>reactor-netty-http</artifactId>
        </dependency>

2.3 configure the app.id, env, apollo.meta same way as before

2.4 configure spring.config.import and other necessary properties on application.properties or application.yml

spring.config.import=apollo://application
apollo.client.extension.enabled=true

2.5 provide a spi Implementation of the interface com.ctrip.framework.apollo.config.data.extension.webclient.customizer.spi.ApolloClientWebClientCustomizerFactory

nobodyiam
nobodyiam previously approved these changes Jun 23, 2021
Copy link
Member

@nobodyiam nobodyiam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great feature and it looks good to me.
However, since it adds a new sdk so I hope it could be reviewed by more committers.

kezhenxu94
kezhenxu94 previously approved these changes Jun 23, 2021
Copy link
Member

@kezhenxu94 kezhenxu94 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create feature, thanks!

I suggest not to mix renaming property / env var names and new feature in a single pull request next time.

@vdiskg
Copy link
Contributor Author

vdiskg commented Jun 23, 2021

Create feature, thanks!

I suggest not to mix renaming property / env var names and new feature in a single pull request next time.

renaming property is strong related to the new feature.
see the
org.springframework.boot.context.properties.bind.Binder#bind
org.springframework.boot.context.properties.source.ConfigurationPropertyName#isValid
if a property name is not valid, the method bind which is used in com.ctrip.framework.apollo.config.data.system.ApolloClientSystemPropertyInitializer will throw an InvalidConfigurationPropertyNameException.

Copy link
Contributor

@Anilople Anilople left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great feature!

I am not familiar with spring.config.import functionality so cannot give more help.

…ollo/config/data/importer/ApolloConfigDataLoaderInitializer.java

Co-authored-by: wxq <Anilople@outlook.com>
@vdiskg vdiskg dismissed stale reviews from kezhenxu94 and nobodyiam via a144e52 June 25, 2021 06:25
@vdiskg vdiskg requested review from Anilople June 25, 2021 08:38
Copy link
Member

@nobodyiam nobodyiam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nobodyiam nobodyiam merged commit 9a6f8e2 into apolloconfig:master Jun 26, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Jun 26, 2021
@nobodyiam nobodyiam added this to the 1.9.0 milestone Jul 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

提供对Spring Boot 2.4新特性spring.config.import的官方支持
5 participants