1. optimize pom dependency 2. optimize demo

pull/71/head
lepdou 3 years ago
parent cf6a2bf8f8
commit cff6466223

@ -33,6 +33,12 @@
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
@ -45,12 +51,6 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<optional>true</optional>
</dependency>
<!-- powermock-module-junit4 -->
<dependency>
<groupId>org.powermock</groupId>

@ -14,11 +14,6 @@
<dependencies>
<!-- Spring Cloud Tencent dependencies start -->
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-tencent-commons</artifactId>
</dependency>
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-tencent-polaris-context</artifactId>
@ -40,11 +35,13 @@
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-loadbalancer</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<optional>true</optional>
</dependency>
<dependency>
@ -53,12 +50,6 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-openfeign-core</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>

@ -43,13 +43,13 @@ public class ConfigurationModifier implements PolarisConfigModifier {
public void modify(ConfigurationImpl configuration) {
configuration.getConfigFile().getServerConnector().setConnectorType("polaris");
if (StringUtils.isEmpty(polarisConfigProperties.getAddresses())) {
if (StringUtils.isEmpty(polarisConfigProperties.getAddress())) {
return;
}
// override polaris config server address
List<String> addresses = AddressUtils
.parseAddressList(polarisConfigProperties.getAddresses());
.parseAddressList(polarisConfigProperties.getAddress());
configuration.getConfigFile().getServerConnector().setAddresses(addresses);
}

@ -37,7 +37,7 @@ public class PolarisConfigProperties {
/**
* Configuration center service address list.
*/
private String addresses;
private String address;
/**
* Whether to automatically update to the spring context when the configuration file.
@ -58,12 +58,12 @@ public class PolarisConfigProperties {
this.enabled = enabled;
}
public String getAddresses() {
return addresses;
public String getAddress() {
return address;
}
public void setAddresses(String addresses) {
this.addresses = addresses;
public void setAddress(String address) {
this.address = address;
}
public boolean isAutoRefresh() {

@ -8,10 +8,10 @@
"sourceType": "com.tencent.cloud.polaris.config.config.PolarisConfigProperties"
},
{
"name": "spring.cloud.polaris.config.addresses",
"name": "spring.cloud.polaris.config.address",
"type": "java.lang.String",
"defaultValue": "",
"description": "The polaris configuration server addresses.",
"description": "The polaris configuration server address.",
"sourceType": "com.tencent.cloud.polaris.config.config.PolarisConfigProperties"
},
{

@ -15,11 +15,6 @@
<dependencies>
<!-- Spring Cloud Tencent dependencies start -->
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-tencent-commons</artifactId>
</dependency>
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-tencent-polaris-context</artifactId>

@ -13,6 +13,7 @@
* 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;
@ -24,7 +25,6 @@ import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.commons.util.InetUtils;
import org.springframework.core.env.Environment;
/**
@ -33,7 +33,7 @@ import org.springframework.core.env.Environment;
* @author Haotian Zhang, Andrew Shan, Jie Cheng
*/
@ConfigurationProperties("spring.cloud.polaris.discovery")
public class PolarisProperties {
public class PolarisDiscoveryProperties {
/**
* The polaris authentication token.
@ -75,11 +75,6 @@ public class PolarisProperties {
@Value("${server.port:}")
private int port;
/**
* Ip address to be registered.
*/
private String ipAddress;
/**
* If instance registered.
*/
@ -101,12 +96,6 @@ public class PolarisProperties {
@Autowired
private Environment environment;
public PolarisProperties(InetUtils inetUtils) {
if (inetUtils != null) {
this.ipAddress = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress();
}
}
/**
* Init properties.
*/
@ -201,14 +190,6 @@ public class PolarisProperties {
this.port = port;
}
public String getIpAddress() {
return ipAddress;
}
public void setIpAddress(String ipAddress) {
this.ipAddress = ipAddress;
}
public String getHealthCheckUrl() {
return healthCheckUrl;
}
@ -222,10 +203,9 @@ public class PolarisProperties {
return "PolarisProperties{" + "token='" + token + '\'' + ", namespace='"
+ namespace + '\'' + ", service='" + service + '\'' + ", weight=" + weight
+ ", version='" + version + '\'' + ", protocol='" + protocol + '\''
+ ", port=" + port + ", ipAddress='" + ipAddress + '\''
+ ", registerEnabled=" + registerEnabled + ", heartbeatEnabled="
+ heartbeatEnabled + ", healthCheckUrl=" + healthCheckUrl
+ ", environment=" + environment + '}';
+ ", port=" + port + '\'' + ", registerEnabled=" + registerEnabled
+ ", heartbeatEnabled=" + heartbeatEnabled + ", healthCheckUrl="
+ healthCheckUrl + ", environment=" + environment + '}';
}
}

@ -13,11 +13,12 @@
* 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.discovery;
import com.tencent.cloud.polaris.PolarisProperties;
import com.tencent.cloud.polaris.PolarisDiscoveryProperties;
import com.tencent.cloud.polaris.discovery.reactive.PolarisReactiveDiscoveryClientConfiguration;
import com.tencent.cloud.polaris.extend.consul.ConsulContextProperties;
import com.tencent.polaris.api.core.ConsumerAPI;
@ -27,7 +28,6 @@ import com.tencent.polaris.client.api.SDKContext;
import com.tencent.polaris.factory.api.DiscoveryAPIFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.cloud.commons.util.InetUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@ -46,8 +46,8 @@ public class PolarisDiscoveryAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public PolarisProperties polarisDiscoveryProperties(InetUtils inetUtils) {
return new PolarisProperties(inetUtils);
public PolarisDiscoveryProperties polarisDiscoveryProperties() {
return new PolarisDiscoveryProperties();
}
@Bean(name = "polarisProvider")

@ -13,6 +13,7 @@
* 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.discovery;
@ -22,7 +23,7 @@ import java.util.Map;
import com.tencent.cloud.common.constant.MetadataConstant.SystemMetadataKey;
import com.tencent.cloud.common.metadata.MetadataContext;
import com.tencent.cloud.common.metadata.MetadataContextHolder;
import com.tencent.cloud.polaris.PolarisProperties;
import com.tencent.cloud.polaris.PolarisDiscoveryProperties;
import com.tencent.polaris.api.core.ConsumerAPI;
import com.tencent.polaris.api.core.ProviderAPI;
import com.tencent.polaris.api.pojo.ServiceInfo;
@ -45,7 +46,7 @@ import org.springframework.stereotype.Component;
public class PolarisDiscoveryHandler {
@Autowired
private PolarisProperties polarisProperties;
private PolarisDiscoveryProperties polarisDiscoveryProperties;
@Autowired
private ProviderAPI providerAPI;
@ -59,7 +60,7 @@ public class PolarisDiscoveryHandler {
* @return list of instances
*/
public InstancesResponse getFilteredInstances(String service) {
String namespace = polarisProperties.getNamespace();
String namespace = polarisDiscoveryProperties.getNamespace();
GetInstancesRequest getInstancesRequest = new GetInstancesRequest();
getInstancesRequest.setNamespace(namespace);
getInstancesRequest.setService(service);
@ -87,7 +88,7 @@ public class PolarisDiscoveryHandler {
* @return list of instances
*/
public InstancesResponse getInstances(String service) {
String namespace = polarisProperties.getNamespace();
String namespace = polarisDiscoveryProperties.getNamespace();
GetAllInstancesRequest request = new GetAllInstancesRequest();
request.setNamespace(namespace);
request.setService(service);
@ -103,7 +104,7 @@ public class PolarisDiscoveryHandler {
* @return service list
*/
public ServicesResponse GetServices() {
String namespace = polarisProperties.getNamespace();
String namespace = polarisDiscoveryProperties.getNamespace();
GetServicesRequest request = new GetServicesRequest();
request.setNamespace(namespace);
return polarisConsumer.getServices(request);

@ -13,6 +13,7 @@
* 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.registry;
@ -21,7 +22,7 @@ import java.net.URI;
import java.util.Map;
import com.tencent.cloud.common.metadata.MetadataContextHolder;
import com.tencent.cloud.polaris.PolarisProperties;
import com.tencent.cloud.polaris.PolarisDiscoveryProperties;
import com.tencent.polaris.client.api.SDKContext;
import org.apache.commons.lang.StringUtils;
@ -36,40 +37,39 @@ import org.springframework.cloud.client.serviceregistry.Registration;
*/
public class PolarisRegistration implements Registration, ServiceInstance {
private final PolarisProperties polarisProperties;
private final PolarisDiscoveryProperties polarisDiscoveryProperties;
private final SDKContext polarisContext;
public PolarisRegistration(PolarisProperties polarisProperties, SDKContext context) {
this.polarisProperties = polarisProperties;
public PolarisRegistration(PolarisDiscoveryProperties polarisDiscoveryProperties,
SDKContext context) {
this.polarisDiscoveryProperties = polarisDiscoveryProperties;
this.polarisContext = context;
}
@Override
public String getServiceId() {
return polarisProperties.getService();
return polarisDiscoveryProperties.getService();
}
@Override
public String getHost() {
if (StringUtils.isNotBlank(polarisProperties.getIpAddress())) {
return polarisProperties.getIpAddress();
}
return polarisContext.getConfig().getGlobal().getAPI().getBindIP();
}
@Override
public int getPort() {
return polarisProperties.getPort();
return polarisDiscoveryProperties.getPort();
}
public void setPort(int port) {
this.polarisProperties.setPort(port);
this.polarisDiscoveryProperties.setPort(port);
}
@Override
public boolean isSecure() {
return StringUtils.equalsIgnoreCase(polarisProperties.getProtocol(), "https");
return StringUtils.equalsIgnoreCase(polarisDiscoveryProperties.getProtocol(),
"https");
}
@Override
@ -82,14 +82,14 @@ public class PolarisRegistration implements Registration, ServiceInstance {
return MetadataContextHolder.get().getAllSystemMetadata();
}
public PolarisProperties getPolarisProperties() {
return polarisProperties;
public PolarisDiscoveryProperties getPolarisProperties() {
return polarisDiscoveryProperties;
}
@Override
public String toString() {
return "PolarisRegistration{" + "polarisProperties=" + polarisProperties
+ ", polarisContext=" + polarisContext + '}';
return "PolarisRegistration{" + "polarisDiscoveryProperties="
+ polarisDiscoveryProperties + ", polarisContext=" + polarisContext + '}';
}
}

@ -13,6 +13,7 @@
* 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.registry;
@ -22,7 +23,7 @@ import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import com.tencent.cloud.common.metadata.config.MetadataLocalProperties;
import com.tencent.cloud.polaris.PolarisProperties;
import com.tencent.cloud.polaris.PolarisDiscoveryProperties;
import com.tencent.cloud.polaris.discovery.PolarisDiscoveryHandler;
import com.tencent.cloud.polaris.util.OkHttpUtil;
import com.tencent.polaris.api.core.ProviderAPI;
@ -56,7 +57,7 @@ public class PolarisServiceRegistry implements ServiceRegistry<Registration> {
private static final int ttl = 5;
private final PolarisProperties polarisProperties;
private final PolarisDiscoveryProperties polarisDiscoveryProperties;
private final PolarisDiscoveryHandler polarisDiscoveryHandler;
@ -64,13 +65,13 @@ public class PolarisServiceRegistry implements ServiceRegistry<Registration> {
private final ScheduledExecutorService heartbeatExecutor;
public PolarisServiceRegistry(PolarisProperties polarisProperties,
public PolarisServiceRegistry(PolarisDiscoveryProperties polarisDiscoveryProperties,
PolarisDiscoveryHandler polarisDiscoveryHandler,
MetadataLocalProperties metadataLocalProperties) {
this.polarisProperties = polarisProperties;
this.polarisDiscoveryProperties = polarisDiscoveryProperties;
this.polarisDiscoveryHandler = polarisDiscoveryHandler;
this.metadataLocalProperties = metadataLocalProperties;
if (polarisProperties.isHeartbeatEnabled()) {
if (polarisDiscoveryProperties.isHeartbeatEnabled()) {
ScheduledThreadPoolExecutor heartbeatExecutor = new ScheduledThreadPoolExecutor(
0, new NamedThreadFactory("spring-cloud-heartbeat"));
heartbeatExecutor.setMaximumPoolSize(1);
@ -90,24 +91,24 @@ public class PolarisServiceRegistry implements ServiceRegistry<Registration> {
}
// Register instance.
InstanceRegisterRequest instanceRegisterRequest = new InstanceRegisterRequest();
instanceRegisterRequest.setNamespace(polarisProperties.getNamespace());
instanceRegisterRequest.setNamespace(polarisDiscoveryProperties.getNamespace());
instanceRegisterRequest.setService(registration.getServiceId());
instanceRegisterRequest.setHost(registration.getHost());
instanceRegisterRequest.setPort(registration.getPort());
instanceRegisterRequest.setToken(polarisProperties.getToken());
instanceRegisterRequest.setToken(polarisDiscoveryProperties.getToken());
if (null != heartbeatExecutor) {
instanceRegisterRequest.setTtl(ttl);
}
instanceRegisterRequest.setMetadata(metadataLocalProperties.getContent());
instanceRegisterRequest.setProtocol(polarisProperties.getProtocol());
instanceRegisterRequest.setVersion(polarisProperties.getVersion());
instanceRegisterRequest.setProtocol(polarisDiscoveryProperties.getProtocol());
instanceRegisterRequest.setVersion(polarisDiscoveryProperties.getVersion());
try {
ProviderAPI providerClient = polarisDiscoveryHandler.getProviderAPI();
providerClient.register(instanceRegisterRequest);
log.info("polaris registry, {} {} {}:{} {} register finished",
polarisProperties.getNamespace(), registration.getServiceId(),
registration.getHost(), registration.getPort(),
metadataLocalProperties.getContent());
polarisDiscoveryProperties.getNamespace(),
registration.getServiceId(), registration.getHost(),
registration.getPort(), metadataLocalProperties.getContent());
if (null != heartbeatExecutor) {
InstanceHeartbeatRequest heartbeatRequest = new InstanceHeartbeatRequest();
@ -134,8 +135,8 @@ public class PolarisServiceRegistry implements ServiceRegistry<Registration> {
}
InstanceDeregisterRequest deRegisterRequest = new InstanceDeregisterRequest();
deRegisterRequest.setToken(polarisProperties.getToken());
deRegisterRequest.setNamespace(polarisProperties.getNamespace());
deRegisterRequest.setToken(polarisDiscoveryProperties.getToken());
deRegisterRequest.setNamespace(polarisDiscoveryProperties.getNamespace());
deRegisterRequest.setService(registration.getServiceId());
deRegisterRequest.setHost(registration.getHost());
deRegisterRequest.setPort(registration.getPort());
@ -177,7 +178,7 @@ public class PolarisServiceRegistry implements ServiceRegistry<Registration> {
}
for (Instance instance : instances) {
if (instance.getHost().equalsIgnoreCase(registration.getHost())
&& instance.getPort() == polarisProperties.getPort()) {
&& instance.getPort() == polarisDiscoveryProperties.getPort()) {
return instance.isHealthy() ? "UP" : "DOWN";
}
}
@ -191,7 +192,8 @@ public class PolarisServiceRegistry implements ServiceRegistry<Registration> {
public void heartbeat(InstanceHeartbeatRequest heartbeatRequest) {
heartbeatExecutor.scheduleWithFixedDelay(() -> {
try {
String healthCheckEndpoint = polarisProperties.getHealthCheckUrl();
String healthCheckEndpoint = polarisDiscoveryProperties
.getHealthCheckUrl();
// First determine whether health-check-url is configured.
// If configured, the service instance health check needs to be executed
// first.

@ -13,12 +13,13 @@
* 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.registry;
import com.tencent.cloud.common.metadata.config.MetadataLocalProperties;
import com.tencent.cloud.polaris.PolarisProperties;
import com.tencent.cloud.polaris.PolarisDiscoveryProperties;
import com.tencent.cloud.polaris.discovery.ConditionalOnPolarisDiscoveryEnabled;
import com.tencent.cloud.polaris.discovery.PolarisDiscoveryAutoConfiguration;
import com.tencent.cloud.polaris.discovery.PolarisDiscoveryHandler;
@ -51,18 +52,18 @@ public class PolarisServiceRegistryAutoConfiguration {
@Bean
public PolarisServiceRegistry polarisServiceRegistry(
PolarisProperties polarisProperties,
PolarisDiscoveryProperties polarisDiscoveryProperties,
PolarisDiscoveryHandler polarisDiscoveryHandler,
MetadataLocalProperties metadataLocalProperties) {
return new PolarisServiceRegistry(polarisProperties, polarisDiscoveryHandler,
metadataLocalProperties);
return new PolarisServiceRegistry(polarisDiscoveryProperties,
polarisDiscoveryHandler, metadataLocalProperties);
}
@Bean
@ConditionalOnBean(AutoServiceRegistrationProperties.class)
public PolarisRegistration polarisRegistration(PolarisProperties polarisProperties,
SDKContext context) {
return new PolarisRegistration(polarisProperties, context);
public PolarisRegistration polarisRegistration(
PolarisDiscoveryProperties polarisDiscoveryProperties, SDKContext context) {
return new PolarisRegistration(polarisDiscoveryProperties, context);
}
@Bean

@ -42,12 +42,6 @@
"defaultValue": "${spring.cloud.polaris.version}",
"description": "polaris discovery service's username to authenticate."
},
{
"name": "spring.cloud.polaris.discovery.ip-address",
"type": "java.lang.String",
"defaultValue": "",
"description": "ip address to be registered to polaris discovery server."
},
{
"name": "spring.cloud.polaris.protocol",
"type": "java.lang.String",

@ -13,22 +13,20 @@
* 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;
import org.junit.Test;
import org.springframework.cloud.commons.util.InetUtils;
import org.springframework.cloud.commons.util.InetUtilsProperties;
import static com.tencent.polaris.test.common.Consts.NAMESPACE_TEST;
import static com.tencent.polaris.test.common.Consts.SERVICE_PROVIDER;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
/**
* Test for {@link PolarisProperties}
* Test for {@link PolarisDiscoveryProperties}
*
* @author Haotian Zhang
*/
@ -36,8 +34,7 @@ public class PolarisPropertiesTest {
@Test
public void testInitAndGetSet() {
PolarisProperties temp = new PolarisProperties(
new InetUtils(new InetUtilsProperties()));
PolarisDiscoveryProperties temp = new PolarisDiscoveryProperties();
try {
temp.setNamespace(NAMESPACE_TEST);
assertThat(temp.getNamespace()).isEqualTo(NAMESPACE_TEST);

@ -13,11 +13,12 @@
* 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.discovery;
import com.tencent.cloud.polaris.PolarisProperties;
import com.tencent.cloud.polaris.PolarisDiscoveryProperties;
import com.tencent.cloud.polaris.context.PolarisContextConfiguration;
import com.tencent.polaris.api.core.ConsumerAPI;
import com.tencent.polaris.api.core.ProviderAPI;
@ -71,7 +72,7 @@ public class PolarisDiscoveryAutoConfigurationTest {
this.contextRunner.run(context -> {
assertThat(context).hasSingleBean(ProviderAPI.class);
assertThat(context).hasSingleBean(ConsumerAPI.class);
assertThat(context).hasSingleBean(PolarisProperties.class);
assertThat(context).hasSingleBean(PolarisDiscoveryProperties.class);
assertThat(context).hasSingleBean(PolarisServiceDiscovery.class);
});
}

@ -15,11 +15,6 @@
<dependencies>
<!-- Spring Cloud Tencent dependencies start -->
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-tencent-commons</artifactId>
</dependency>
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-tencent-polaris-context</artifactId>

@ -15,11 +15,6 @@
<dependencies>
<!-- Spring Cloud Tencent dependencies start -->
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-tencent-commons</artifactId>
</dependency>
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-tencent-polaris-context</artifactId>
@ -32,6 +27,11 @@
<artifactId>polaris-router-factory</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
</dependency>
<dependency>
<groupId>com.tencent.polaris</groupId>
<artifactId>polaris-test-common</artifactId>
@ -39,11 +39,6 @@
</dependency>
<!-- Polaris dependencies end -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>

@ -47,16 +47,6 @@
<artifactId>spring-cloud-commons</artifactId>
</dependency>
<dependency>
<groupId>com.netflix.ribbon</groupId>
<artifactId>ribbon-loadbalancer</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>

@ -43,7 +43,8 @@ public class MetadataFirstFeignInterceptor implements RequestInterceptor, Ordere
MetadataContext metadataContext = MetadataContextHolder.get();
// TODO The peer namespace is temporarily the same as the local namespace
metadataContext.putSystemMetadata(MetadataConstant.SystemMetadataKey.PEER_NAMESPACE,
metadataContext.putSystemMetadata(
MetadataConstant.SystemMetadataKey.PEER_NAMESPACE,
MetadataContext.LOCAL_NAMESPACE);
metadataContext.putSystemMetadata(MetadataConstant.SystemMetadataKey.PEER_SERVICE,
requestTemplate.feignTarget().name());

@ -64,7 +64,6 @@
<properties>
<revision>1.2.0-Hoxton.SR9-SNAPSHOT</revision>
<polaris.version>1.3.0-SNAPSHOT</polaris.version>
<tomcat.version>10.0.0-M6</tomcat.version>
<powermock.version>2.0.0</powermock.version>
<!-- Maven Plugin Versions -->
@ -84,12 +83,6 @@
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-websocket</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-tencent-commons</artifactId>
@ -98,37 +91,38 @@
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-starter-tencent-polaris-ratelimit</artifactId>
<artifactId>spring-cloud-tencent-polaris-context</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-starter-tencent-polaris-circuitbreaker</artifactId>
<artifactId>spring-cloud-starter-tencent-metadata-transfer</artifactId>
<version>${revision}</version>
</dependency>
<!-- polaris starter-->
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-starter-tencent-polaris-router</artifactId>
<artifactId>spring-cloud-starter-tencent-polaris-ratelimit</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-starter-tencent-polaris-config</artifactId>
<artifactId>spring-cloud-starter-tencent-polaris-circuitbreaker</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-tencent-polaris-context</artifactId>
<artifactId>spring-cloud-starter-tencent-polaris-router</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-starter-tencent-metadata-transfer</artifactId>
<artifactId>spring-cloud-starter-tencent-polaris-config</artifactId>
<version>${revision}</version>
</dependency>

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

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

@ -19,18 +19,11 @@
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- Spring Cloud Tencent dependency -->
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-starter-tencent-polaris-config</artifactId>
</dependency>
</dependencies>
</project>

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

@ -1,15 +0,0 @@
log4j.rootLogger=DEBUG,console,FILE
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.threshold=INFO
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d{yyyy-MM-dd HH\:mm\:ss} [%5p] - %c -%F(%L) -%m%n
log4j.appender.FILE=org.apache.log4j.RollingFileAppender
log4j.appender.FILE.Append=true
log4j.appender.FILE.File=applog/%d{yyyy-MM-dd}/%d{yyyy-MM-dd}.log
log4j.appender.FILE.Threshold=INFO
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=%d{yyyy-MM-dd HH\:mm\:ss} [%5p] - %c -%F(%L) -%m%n
log4j.appender.FILE.MaxFileSize=10MB

@ -1,28 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="60 seconds" debug="false">
<contextName>logback</contextName>
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<appender name="logFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
<Prudent>true</Prudent>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>
applog/%d{yyyy-MM-dd}/%d{yyyy-MM-dd}.log
</FileNamePattern>
</rollingPolicy>
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>
%d{yyyy-MM-dd HH:mm:ss} -%msg%n
</Pattern>
</layout>
</appender>
<root level="info">
<appender-ref ref="console"/>
<appender-ref ref="logFile"/>
</root>
</configuration>

@ -15,8 +15,8 @@
<dependencies>
<dependency>
<artifactId>spring-cloud-starter-tencent-polaris-discovery</artifactId>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-starter-tencent-polaris-discovery</artifactId>
</dependency>
<!-- <dependency>-->

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

@ -1,16 +0,0 @@
global:
system:
discoverCluster:
sameAsBuiltin: true
healthCheckCluster:
sameAsBuiltin: true
#global:
# system:
# discoverCluster:
# sameAsBuiltin: false
# namespace: Polaris
# service: polaris.discover
# healthCheckCluster:
# sameAsBuiltin: false
# namespace: Polaris
# service: polaris.healthcheck

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

@ -1,9 +0,0 @@
server:
session-timeout: 1800
port: 48081
spring:
application:
name: GatewayCalleeService
cloud:
polaris:
address: grpc://127.0.0.1:8091

@ -0,0 +1,10 @@
server:
session-timeout: 1800
port: 48081
spring:
application:
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
namespace: default

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

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

@ -28,9 +28,5 @@
<artifactId>spring-cloud-starter-tencent-polaris-ratelimit</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator-autoconfigure</artifactId>
</dependency>
</dependencies>
</project>

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

@ -93,11 +93,6 @@
</dependency>
<!-- Polaris dependencies end -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-commons</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>

@ -1,52 +0,0 @@
/*
* 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 org.springframework.boot.context.properties.ConfigurationProperties;
/**
* Because polaris-context is initialized in the bootstrap phase, the initialization of
* InetUtilsProperties is required. The impact on user usage is that
* spring.cloud.inetutils.defaultIpAddress needs to be configured in bootstrap.yml to take
* effect.
*
* @see org.springframework.cloud.commons.util.InetUtilsProperties
*/
@ConfigurationProperties(InetUtilsProperties.PREFIX)
public class InetUtilsProperties {
/**
* Prefix for the Inet Utils properties.
*/
public static final String PREFIX = "spring.cloud.inetutils";
/**
* The default IP address. Used in case of errors.
*/
private String defaultIpAddress = "127.0.0.1";
String getDefaultIpAddress() {
return defaultIpAddress;
}
void setDefaultIpAddress(String defaultIpAddress) {
this.defaultIpAddress = defaultIpAddress;
}
}

@ -13,6 +13,7 @@
* 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;
@ -36,8 +37,7 @@ import org.springframework.context.annotation.Bean;
*
* @author Haotian Zhang
*/
@EnableConfigurationProperties({ PolarisContextProperties.class,
InetUtilsProperties.class })
@EnableConfigurationProperties({ PolarisContextProperties.class })
public class PolarisContextConfiguration {
@Bean(name = "polarisContext", initMethod = "init", destroyMethod = "destroy")
@ -49,7 +49,7 @@ public class PolarisContextConfiguration {
@Bean
@ConditionalOnMissingBean
public PolarisConfigModifier polarisConfigModifier() {
public ModifyAddress polarisConfigModifier() {
return new ModifyAddress();
}

@ -13,6 +13,7 @@
* 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;
@ -29,7 +30,6 @@ import com.tencent.polaris.factory.config.ConfigurationImpl;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.core.env.Environment;
import org.springframework.util.CollectionUtils;
@ -48,13 +48,14 @@ public class PolarisContextProperties {
private String address;
/**
* polaris namespace.
* current server local ip address.
*/
@Value("${spring.cloud.polaris.namespace:#{'default'}}")
private String namespace;
private String localIpAddress;
@Autowired
private InetUtilsProperties inetUtilsProperties;
/**
* polaris namespace.
*/
private String namespace = "default";
@Autowired
private Environment environment;
@ -81,10 +82,8 @@ public class PolarisContextProperties {
}
private String getHost() {
String defaultIpAddress = inetUtilsProperties.getDefaultIpAddress();
if (!StringUtils.isBlank(defaultIpAddress)
&& !defaultIpAddress.equals("127.0.0.1")) {
return defaultIpAddress;
if (StringUtils.isNotBlank(localIpAddress)) {
return localIpAddress;
}
return environment.getProperty("spring.cloud.client.ip-address");
}
@ -97,6 +96,14 @@ public class PolarisContextProperties {
this.address = address;
}
String getLocalIpAddress() {
return localIpAddress;
}
void setLocalIpAddress(String localIpAddress) {
this.localIpAddress = localIpAddress;
}
public String getNamespace() {
return namespace;
}

@ -17,7 +17,14 @@
"name": "spring.cloud.polaris.namespace",
"type": "java.lang.String",
"description": "polaris namespace",
"default": "default",
"sourceType": "com.tencent.cloud.polaris.context.PolarisContextProperties"
},
{
"name": "spring.cloud.polaris.local-ip-address",
"type": "java.lang.String",
"defaultValue": "",
"description": "current server local ip address."
}
],
"hints": []

@ -37,11 +37,15 @@ public class PolarisContextGetHostTest {
@Autowired
private SDKContext polarisContext;
@Autowired
private PolarisContextProperties polarisContextProperties;
@Test
public void testGetConfigHost() {
String bindIP = polarisContext.getConfig().getGlobal().getAPI().getBindIP();
Assert.assertFalse(StringUtils.isBlank(bindIP));
Assert.assertEquals(bindIP, "192.168.1.1");
Assert.assertEquals(polarisContextProperties.getNamespace(), "dev");
}
}

@ -1,7 +1,6 @@
spring:
cloud:
polaris:
local-ip-address: 192.168.1.1
address: grpc://127.0.0.1:8091
namespace: dev
inetutils:
defaultIpAddress: 192.168.1.1

Loading…
Cancel
Save