parent
085ae91f77
commit
fa5d0eefb8
@ -1,5 +1,4 @@
|
|||||||
server:
|
server:
|
||||||
session-timeout: 1800
|
|
||||||
port: 48081
|
port: 48081
|
||||||
spring:
|
spring:
|
||||||
application:
|
application:
|
@ -1,10 +1,11 @@
|
|||||||
server:
|
server:
|
||||||
session-timeout: 1800
|
|
||||||
port: 48080
|
port: 48080
|
||||||
spring:
|
spring:
|
||||||
application:
|
application:
|
||||||
name: DiscoveryCallerService
|
name: DiscoveryCallerService
|
||||||
cloud:
|
cloud:
|
||||||
|
loadbalancer:
|
||||||
|
configurations: default
|
||||||
polaris:
|
polaris:
|
||||||
address: grpc://127.0.0.1:8091
|
address: grpc://127.0.0.1:8091
|
||||||
consul:
|
consul:
|
@ -1,37 +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.circuitbreaker.feign;
|
|
||||||
|
|
||||||
import feign.Client;
|
|
||||||
import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
|
|
||||||
import org.springframework.cloud.openfeign.ribbon.CachingSpringLoadBalancerFactory;
|
|
||||||
import org.springframework.cloud.openfeign.ribbon.LoadBalancerFeignClient;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Wrap for {@link LoadBalancerFeignClient}
|
|
||||||
*
|
|
||||||
* @author Haotian Zhang
|
|
||||||
*/
|
|
||||||
public class PolarisLoadBalancerFeignClient extends LoadBalancerFeignClient {
|
|
||||||
|
|
||||||
public PolarisLoadBalancerFeignClient(Client delegate,
|
|
||||||
CachingSpringLoadBalancerFactory lbClientFactory,
|
|
||||||
SpringClientFactory clientFactory) {
|
|
||||||
super(delegate, lbClientFactory, clientFactory);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,5 +1,4 @@
|
|||||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||||
com.tencent.cloud.polaris.discovery.PolarisDiscoveryAutoConfiguration,\
|
com.tencent.cloud.polaris.discovery.PolarisDiscoveryAutoConfiguration,\
|
||||||
com.tencent.cloud.polaris.ribbon.PolarisDiscoveryRibbonAutoConfiguration,\
|
|
||||||
com.tencent.cloud.polaris.registry.PolarisServiceRegistryAutoConfiguration
|
com.tencent.cloud.polaris.registry.PolarisServiceRegistryAutoConfiguration
|
||||||
|
|
||||||
|
@ -0,0 +1,112 @@
|
|||||||
|
/*
|
||||||
|
* 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.router;
|
||||||
|
|
||||||
|
import com.tencent.cloud.constant.LoadbalancerConstant;
|
||||||
|
import com.tencent.cloud.polaris.router.PolarisRouterServiceInstanceListSupplier;
|
||||||
|
import com.tencent.polaris.api.exception.PolarisException;
|
||||||
|
import com.tencent.polaris.client.api.SDKContext;
|
||||||
|
import com.tencent.polaris.factory.api.RouterAPIFactory;
|
||||||
|
import com.tencent.polaris.router.api.core.RouterAPI;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
|
import org.springframework.cloud.client.ConditionalOnBlockingDiscoveryEnabled;
|
||||||
|
import org.springframework.cloud.client.ConditionalOnReactiveDiscoveryEnabled;
|
||||||
|
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||||
|
import org.springframework.cloud.client.discovery.ReactiveDiscoveryClient;
|
||||||
|
import org.springframework.cloud.loadbalancer.core.ServiceInstanceListSupplier;
|
||||||
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.core.annotation.Order;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-configuration Ribbon for Polaris.
|
||||||
|
*
|
||||||
|
* @author Haotian Zhang
|
||||||
|
*/
|
||||||
|
@Configuration()
|
||||||
|
@EnableConfigurationProperties
|
||||||
|
@ConditionalOnProperty(value = "spring.cloud.polaris.loadbalancer.enabled", matchIfMissing = true)
|
||||||
|
public class PolarisRouterAutoConfiguration {
|
||||||
|
|
||||||
|
@Bean(name = "polarisRoute")
|
||||||
|
@ConditionalOnMissingBean
|
||||||
|
public RouterAPI polarisRouter(SDKContext polarisContext) throws PolarisException {
|
||||||
|
return RouterAPIFactory.createRouterAPIByContext(polarisContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
@ConditionalOnReactiveDiscoveryEnabled
|
||||||
|
@Order(LoadbalancerConstant.ROUTER_SERVICE_INSTANCE_SUPPLIER_ORDER - 1000)
|
||||||
|
public static class ReactiveSupportConfiguration {
|
||||||
|
|
||||||
|
// @Bean
|
||||||
|
// @ConditionalOnBean(ReactiveDiscoveryClient.class)
|
||||||
|
// @ConditionalOnMissingBean
|
||||||
|
// @ConditionalOnProperty(value = "spring.cloud.loadbalancer.configurations", havingValue = "default", matchIfMissing = true)
|
||||||
|
// public ServiceInstanceListSupplier discoveryClientServiceInstanceListSupplier(RouterAPI routerAPI,
|
||||||
|
// ConfigurableApplicationContext context) {
|
||||||
|
// return new PolarisRouterServiceInstanceListSupplier(ServiceInstanceListSupplier.builder().withDiscoveryClient()
|
||||||
|
// .build(context), routerAPI);
|
||||||
|
// }
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnBean(ReactiveDiscoveryClient.class)
|
||||||
|
@ConditionalOnMissingBean
|
||||||
|
@ConditionalOnProperty(value = "spring.cloud.loadbalancer.configurations", havingValue = "zone-preference", matchIfMissing = true)
|
||||||
|
public ServiceInstanceListSupplier polarisRouterDiscoveryClientServiceInstanceListSupplier(RouterAPI routerAPI,
|
||||||
|
ConfigurableApplicationContext context) {
|
||||||
|
return new PolarisRouterServiceInstanceListSupplier(ServiceInstanceListSupplier.builder().withDiscoveryClient()
|
||||||
|
.withZonePreference()
|
||||||
|
.build(context), routerAPI);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
@ConditionalOnBlockingDiscoveryEnabled
|
||||||
|
@Order(LoadbalancerConstant.ROUTER_SERVICE_INSTANCE_SUPPLIER_ORDER + 1 - 1000)
|
||||||
|
public static class BlockingSupportConfiguration {
|
||||||
|
|
||||||
|
// @Bean
|
||||||
|
// @ConditionalOnBean(DiscoveryClient.class)
|
||||||
|
// @ConditionalOnMissingBean
|
||||||
|
// @ConditionalOnProperty(value = "spring.cloud.loadbalancer.configurations", havingValue = "default", matchIfMissing = true)
|
||||||
|
// public ServiceInstanceListSupplier discoveryClientServiceInstanceListSupplier(
|
||||||
|
// RouterAPI routerAPI,
|
||||||
|
// ConfigurableApplicationContext context) {
|
||||||
|
// return new PolarisRouterServiceInstanceListSupplier(ServiceInstanceListSupplier.builder().withBlockingDiscoveryClient()
|
||||||
|
// .build(context), routerAPI);
|
||||||
|
// }
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnBean(DiscoveryClient.class)
|
||||||
|
@ConditionalOnMissingBean
|
||||||
|
@ConditionalOnProperty(value = "spring.cloud.loadbalancer.configurations", havingValue = "zone-preference", matchIfMissing = true)
|
||||||
|
public ServiceInstanceListSupplier polarisRouterDiscoveryClientServiceInstanceListSupplier(RouterAPI routerAPI,
|
||||||
|
ConfigurableApplicationContext context) {
|
||||||
|
return new PolarisRouterServiceInstanceListSupplier(ServiceInstanceListSupplier.builder().withBlockingDiscoveryClient()
|
||||||
|
.withZonePreference().build(context), routerAPI);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
20
spring-cloud-tencent-starters/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/PolarisRoutingLoadBalancer.java → spring-cloud-tencent-starters/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/PolarisRouterServiceInstanceListSupplier.java
20
spring-cloud-tencent-starters/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/PolarisRoutingLoadBalancer.java → spring-cloud-tencent-starters/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/PolarisRouterServiceInstanceListSupplier.java
@ -1,51 +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.router.config;
|
|
||||||
|
|
||||||
import com.tencent.polaris.api.exception.PolarisException;
|
|
||||||
import com.tencent.polaris.client.api.SDKContext;
|
|
||||||
import com.tencent.polaris.factory.api.RouterAPIFactory;
|
|
||||||
import com.tencent.polaris.router.api.core.RouterAPI;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Auto-configuration Ribbon for Polaris.
|
|
||||||
*
|
|
||||||
* @author Haotian Zhang
|
|
||||||
*/
|
|
||||||
@Configuration()
|
|
||||||
@EnableConfigurationProperties
|
|
||||||
@ConditionalOnProperty(value = "spring.cloud.polaris.loadbalancer.enabled", matchIfMissing = true)
|
|
||||||
public class PolarisRouterAutoConfiguration {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
@ConditionalOnMissingBean
|
|
||||||
public PolarisRouterProperties polarisRibbonProperties() {
|
|
||||||
return new PolarisRouterProperties();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean(name = "polarisRoute")
|
|
||||||
@ConditionalOnMissingBean
|
|
||||||
public RouterAPI polarisRouter(SDKContext polarisContext) throws PolarisException {
|
|
||||||
return RouterAPIFactory.createRouterAPIByContext(polarisContext);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,64 +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.router.config;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Haotian Zhang
|
|
||||||
*/
|
|
||||||
@ConfigurationProperties("spring.cloud.polaris.ribbon")
|
|
||||||
public class PolarisRouterProperties {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否开启负载均衡
|
|
||||||
*/
|
|
||||||
@Value("${spring.cloud.polaris.loadbalancer.enabled:#{true}}")
|
|
||||||
private Boolean loadbalancerEnabled;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* loadbalnce strategy
|
|
||||||
*/
|
|
||||||
@Value("${spring.cloud.polaris.loadbalancer.strategy:#{'weightedRandom'}}")
|
|
||||||
private String policy;
|
|
||||||
|
|
||||||
public String getPolicy() {
|
|
||||||
return policy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPolicy(String policy) {
|
|
||||||
this.policy = policy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean getLoadbalancerEnabled() {
|
|
||||||
return loadbalancerEnabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLoadbalancerEnabled(Boolean loadbalancerEnabled) {
|
|
||||||
this.loadbalancerEnabled = loadbalancerEnabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "PolarisRibbonProperties{" +
|
|
||||||
"loadbalancerEnabled=" + loadbalancerEnabled +
|
|
||||||
", policy='" + policy + '\'' +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,53 +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.router.rule;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Haotian Zhang
|
|
||||||
*/
|
|
||||||
public enum PolarisLoadBalanceRule {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 加权随机
|
|
||||||
*/
|
|
||||||
WEIGHTED_RANDOM_RULE("weighted_random");
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 策略
|
|
||||||
*/
|
|
||||||
String policy;
|
|
||||||
|
|
||||||
PolarisLoadBalanceRule(String strategy) {
|
|
||||||
this.policy = strategy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static PolarisLoadBalanceRule fromStrategy(String strategy) {
|
|
||||||
return Arrays.stream(values()).filter(t -> t.getPolicy().equals(strategy)).findAny()
|
|
||||||
.orElse(WEIGHTED_RANDOM_RULE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@link #policy}的getter方法。
|
|
||||||
*/
|
|
||||||
public String getPolicy() {
|
|
||||||
return policy;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,2 +1,2 @@
|
|||||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||||
com.tencent.cloud.polaris.router.config.PolarisRouterAutoConfiguration
|
com.tencent.cloud.polaris.router.PolarisRouterAutoConfiguration
|
||||||
|
Loading…
Reference in new issue