Merge pull request #73 from lepdou/fix_autoconfiguration

rollback init polaris-context to application phase
pull/74/head
Haotian Zhang 3 years ago committed by GitHub
commit 9f5bc3b0b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -14,5 +14,6 @@
- [feat:optimize metadata module.](https://github.com/Tencent/spring-cloud-tencent/pull/70)
- [feat: optimize pom dependency and demo](https://github.com/Tencent/spring-cloud-tencent/pull/71)
- [feat:upgrade polaris version to 1.3.0.](https://github.com/Tencent/spring-cloud-tencent/pull/72)
- [feat:rollback init polaris-context to application phase](https://github.com/Tencent/spring-cloud-tencent/pull/73)

@ -1,18 +1,18 @@
/*
* Tencent is pleased to support the open source community by making Spring Cloud Tencent available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
*/
package com.tencent.cloud.polaris.config;
@ -20,6 +20,7 @@ package com.tencent.cloud.polaris.config;
import com.tencent.cloud.polaris.config.adapter.PolarisConfigFileLocator;
import com.tencent.cloud.polaris.config.adapter.PolarisPropertySourceManager;
import com.tencent.cloud.polaris.config.config.PolarisConfigProperties;
import com.tencent.cloud.polaris.context.PolarisContextConfiguration;
import com.tencent.cloud.polaris.context.PolarisContextProperties;
import com.tencent.polaris.client.api.SDKContext;
import com.tencent.polaris.configuration.api.core.ConfigFileService;
@ -28,6 +29,7 @@ import com.tencent.polaris.configuration.factory.ConfigFileServiceFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
/**
* polaris config module auto configuration at bootstrap phase.
@ -37,6 +39,7 @@ import org.springframework.context.annotation.Configuration;
@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty(value = "spring.cloud.polaris.config.enabled",
matchIfMissing = true)
@Import(PolarisContextConfiguration.class)
public class PolarisConfigBootstrapAutoConfiguration {
@Bean

@ -5,7 +5,7 @@ spring:
name: polaris-circuitbreaker-example-a
cloud:
polaris:
address: grpc://159.75.195.18:8091 # The demo address officially provided by Polaris can be accessed directly http://159.75.195.18
address: grpc://127.0.0.1:8091
namespace: default
feign:
hystrix:

@ -5,6 +5,6 @@ spring:
name: polaris-circuitbreaker-example-b
cloud:
polaris:
address: grpc://159.75.195.18:8091 # The demo address officially provided by Polaris can be accessed directly http://159.75.195.18
address: grpc://127.0.0.1:8091
namespace: default
is-throw-runtime-exception: false

@ -7,7 +7,7 @@ spring:
polaris:
namespace: default
config:
address: grpc://159.75.195.18:8093 # The demo address officially provided by Polaris can be accessed directly http://159.75.195.18
address: grpc://127.0.0.1:8093
auto-refresh: true # auto refresh when config file changed
groups:
- name: ${spring.application.name} # group name

@ -5,7 +5,7 @@ spring:
name: DiscoveryCalleeService
cloud:
polaris:
address: grpc://159.75.195.18:8091 # The demo address officially provided by Polaris can be accessed directly http://159.75.195.18
address: grpc://127.0.0.1:8091
namespace: default
# consul:
# port: 8500

@ -6,7 +6,7 @@ spring:
name: DiscoveryCallerService
cloud:
polaris:
address: grpc://159.75.195.18:8091 # The demo address officially provided by Polaris can be accessed directly http://159.75.195.18
address: grpc://127.0.0.1:8091
namespace: default
discovery:
heartbeat:

@ -1,6 +0,0 @@
global:
system:
discoverCluster:
sameAsBuiltin: true
healthCheckCluster:
sameAsBuiltin: true

@ -6,5 +6,5 @@ spring:
name: GatewayCalleeService
cloud:
polaris:
address: grpc://159.75.195.18:8091 # The demo address officially provided by Polaris can be accessed directly http://159.75.195.18
address: grpc://127.0.0.1:8091
namespace: default

@ -12,7 +12,7 @@ spring:
transitive:
- a
polaris:
address: grpc://159.75.195.18:8091 # The demo address officially provided by Polaris can be accessed directly http://159.75.195.18
address: grpc://127.0.0.1:8091
namespace: default
gateway:
discovery:

@ -6,7 +6,7 @@ spring:
name: GatewayZuulService
cloud:
polaris:
address: grpc://159.75.195.18:8091 # The demo address officially provided by Polaris can be accessed directly http://159.75.195.18
address: grpc://127.0.0.1:8091
namespace: default
tencent:
metadata:

@ -5,5 +5,5 @@ spring:
name: RateLimitCalleeService
cloud:
polaris:
address: grpc://159.75.195.18:8091 # The demo address officially provided by Polaris can be accessed directly http://159.75.195.18
address: grpc://127.0.0.1:8091
namespace: default

@ -0,0 +1,57 @@
/*
* Tencent is pleased to support the open source community by making Spring Cloud Tencent available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
*/
package com.tencent.cloud.polaris.context;
import java.util.List;
import com.tencent.cloud.common.constant.ContextConstant;
import com.tencent.cloud.common.util.AddressUtils;
import com.tencent.polaris.factory.config.ConfigurationImpl;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
/**
* Modify polaris server address.
*
* @author lepdou 2022-03-10
*/
public class ModifyAddress implements PolarisConfigModifier {
@Autowired
private PolarisContextProperties properties;
@Override
public void modify(ConfigurationImpl configuration) {
if (StringUtils.isBlank(properties.getAddress())) {
return;
}
List<String> addresses = AddressUtils
.parseAddressList(properties.getAddress());
configuration.getGlobal().getServerConnector().setAddresses(addresses);
}
@Override
public int getOrder() {
return ContextConstant.ModifierOrder.FIRST;
}
}

@ -18,16 +18,9 @@
package com.tencent.cloud.polaris.context;
import java.util.List;
import com.tencent.cloud.common.constant.ContextConstant.ModifierOrder;
import com.tencent.cloud.common.util.AddressUtils;
import com.tencent.polaris.api.exception.PolarisException;
import com.tencent.polaris.client.api.SDKContext;
import com.tencent.polaris.factory.config.ConfigurationImpl;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
@ -52,29 +45,4 @@ public class PolarisContextConfiguration {
public ModifyAddress polarisConfigModifier() {
return new ModifyAddress();
}
private static class ModifyAddress implements PolarisConfigModifier {
@Autowired
private PolarisContextProperties properties;
@Override
public void modify(ConfigurationImpl configuration) {
if (StringUtils.isBlank(properties.getAddress())) {
return;
}
List<String> addresses = AddressUtils
.parseAddressList(properties.getAddress());
configuration.getGlobal().getServerConnector().setAddresses(addresses);
}
@Override
public int getOrder() {
return ModifierOrder.FIRST;
}
}
}

@ -1 +1 @@
org.springframework.cloud.bootstrap.BootstrapConfiguration=com.tencent.cloud.polaris.context.PolarisContextConfiguration
org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.tencent.cloud.polaris.context.PolarisContextConfiguration

Loading…
Cancel
Save