From e7521c02c9c0229810ae480a7561665e8ddacbc2 Mon Sep 17 00:00:00 2001 From: theonefx Date: Tue, 23 Feb 2021 18:06:31 +0800 Subject: [PATCH] 2020 build done, unit test failed --- pom.xml | 22 +- spring-cloud-alibaba-dependencies/pom.xml | 2 +- .../pom.xml | 5 + .../examples/ConsumerSCLBApplication.java | 20 +- .../fallback/EchoServiceFallback.java | 44 ---- .../fallback/EchoServiceFallbackFactory.java | 34 --- .../cloud/examples/service/EchoService.java | 5 +- .../pom.xml | 6 + .../zuul/SentinelZuulAutoConfiguration.java | 204 +++++++++--------- .../main/resources/META-INF/spring.factories | 1 - .../pom.xml | 6 + .../ribbon/ConditionalOnRibbonNacos.java | 31 --- .../cloud/nacos/ribbon/ExtendBalancer.java | 38 ---- .../NacosRibbonClientConfiguration.java | 62 ------ .../alibaba/cloud/nacos/ribbon/NacosRule.java | 100 --------- .../cloud/nacos/ribbon/NacosServer.java | 76 ------- .../nacos/ribbon/NacosServerIntrospector.java | 47 ---- .../cloud/nacos/ribbon/NacosServerList.java | 87 -------- .../ribbon/RibbonNacosAutoConfiguration.java | 42 ---- .../main/resources/META-INF/spring.factories | 1 - .../NacosRibbonClientConfigurationTests.java | 78 ------- ...acosRibbonClientPropertyOverrideTests.java | 81 ------- .../nacos/ribbon/NacosServerListTests.java | 165 -------------- .../SeataFeignBlockingLoadBalancerClient.java | 10 +- .../SeataFeignClientAutoConfiguration.java | 14 +- .../seata/feign/SeataFeignObjectWrapper.java | 55 ++--- .../seata/feign/SeataHystrixFeignBuilder.java | 76 +++---- .../feign/SeataLoadBalancerFeignClient.java | 93 ++++---- .../SeataHystrixAutoConfiguration.java | 37 ---- .../SeataHystrixConcurrencyStrategy.java | 175 --------------- .../main/resources/META-INF/spring.factories | 3 +- .../pom.xml | 12 ++ .../cloud/sentinel/feign/SentinelFeign.java | 62 +++--- .../feign/SentinelInvocationHandler.java | 32 +-- .../sentinel/ContextIdSentinelFeignTests.java | 3 +- .../cloud/sentinel/SentinelFeignTests.java | 3 +- .../consul/SidecarConsulAutoRegistration.java | 2 +- .../SidecarNacosDiscoveryProperties.java | 2 +- .../RocketMQBusEnvironmentPostProcessor.java | 2 +- .../pom.xml | 7 + .../integration/RocketMQMessageHandler.java | 2 +- 41 files changed, 339 insertions(+), 1408 deletions(-) delete mode 100644 spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-consumer-example/src/main/java/com/alibaba/cloud/examples/fallback/EchoServiceFallback.java delete mode 100644 spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-consumer-example/src/main/java/com/alibaba/cloud/examples/fallback/EchoServiceFallbackFactory.java delete mode 100644 spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/ConditionalOnRibbonNacos.java delete mode 100644 spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/ExtendBalancer.java delete mode 100644 spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/NacosRibbonClientConfiguration.java delete mode 100644 spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/NacosRule.java delete mode 100644 spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/NacosServer.java delete mode 100644 spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/NacosServerIntrospector.java delete mode 100644 spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/NacosServerList.java delete mode 100644 spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/RibbonNacosAutoConfiguration.java delete mode 100644 spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/ribbon/NacosRibbonClientConfigurationTests.java delete mode 100644 spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/ribbon/NacosRibbonClientPropertyOverrideTests.java delete mode 100644 spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/ribbon/NacosServerListTests.java delete mode 100644 spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/hystrix/SeataHystrixAutoConfiguration.java delete mode 100644 spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/hystrix/SeataHystrixConcurrencyStrategy.java diff --git a/pom.xml b/pom.xml index 027f8925..c8dc2134 100644 --- a/pom.xml +++ b/pom.xml @@ -80,7 +80,7 @@ - 2.2.6-SNAPSHOT + 2021.1-SNAPSHOT 2020.0.1 @@ -195,6 +195,21 @@ jacoco-maven-plugin ${jacoco.version} + + + + io.spring.javaformat + spring-javaformat-maven-plugin + ${spring-javaformat.version} + + + validate + + true + + + + @@ -219,10 +234,6 @@ - - io.spring.javaformat - spring-javaformat-maven-plugin - org.apache.maven.plugins maven-checkstyle-plugin @@ -241,6 +252,7 @@ true true warning + true diff --git a/spring-cloud-alibaba-dependencies/pom.xml b/spring-cloud-alibaba-dependencies/pom.xml index 18599e51..1302d875 100644 --- a/spring-cloud-alibaba-dependencies/pom.xml +++ b/spring-cloud-alibaba-dependencies/pom.xml @@ -18,7 +18,7 @@ Spring Cloud Alibaba Dependencies - 2.2.6-SNAPSHOT + 2021.1-SNAPSHOT 1.8.0 1.3.0 1.4.1 diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/pom.xml b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/pom.xml index 2771c802..fd026389 100644 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/pom.xml +++ b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/pom.xml @@ -47,6 +47,11 @@ spring-cloud-starter-alibaba-sentinel + + org.springframework.cloud + spring-cloud-commons + + org.springframework.cloud spring-cloud-starter-openfeign diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/src/main/java/com/alibaba/cloud/examples/ConsumerSCLBApplication.java b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/src/main/java/com/alibaba/cloud/examples/ConsumerSCLBApplication.java index 9cb57f9b..2407d7ea 100644 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/src/main/java/com/alibaba/cloud/examples/ConsumerSCLBApplication.java +++ b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/src/main/java/com/alibaba/cloud/examples/ConsumerSCLBApplication.java @@ -32,11 +32,10 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.ServiceInstance; import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.client.loadbalancer.EmptyResponse; import org.springframework.cloud.client.loadbalancer.LoadBalanced; -import org.springframework.cloud.client.loadbalancer.reactive.DefaultResponse; -import org.springframework.cloud.client.loadbalancer.reactive.EmptyResponse; -import org.springframework.cloud.client.loadbalancer.reactive.Request; -import org.springframework.cloud.client.loadbalancer.reactive.Response; +import org.springframework.cloud.client.loadbalancer.Response; +import org.springframework.cloud.client.loadbalancer.DefaultResponse; import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClient; import org.springframework.cloud.loadbalancer.core.NoopServiceInstanceListSupplier; import org.springframework.cloud.loadbalancer.core.ReactorServiceInstanceLoadBalancer; @@ -103,9 +102,17 @@ public class ConsumerSCLBApplication { this.random = new Random(); } + @Override - public Mono> choose(Request request) { - log.info("random spring cloud loadbalacer active -.-"); + public Mono> choose(org.springframework.cloud.client.loadbalancer.Request request) { + ServiceInstanceListSupplier supplier = serviceInstanceListSupplierProvider + .getIfAvailable(NoopServiceInstanceListSupplier::new); + + return supplier.get().next().map(this::getInstanceResponse); + } + + @Override + public Mono> choose() { ServiceInstanceListSupplier supplier = serviceInstanceListSupplierProvider .getIfAvailable(NoopServiceInstanceListSupplier::new); return supplier.get().next().map(this::getInstanceResponse); @@ -120,7 +127,6 @@ public class ConsumerSCLBApplication { return new DefaultResponse(instance); } - } @FeignClient(name = "service-provider", fallback = EchoServiceFallback.class, diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-consumer-example/src/main/java/com/alibaba/cloud/examples/fallback/EchoServiceFallback.java b/spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-consumer-example/src/main/java/com/alibaba/cloud/examples/fallback/EchoServiceFallback.java deleted file mode 100644 index 2e6a9aab..00000000 --- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-consumer-example/src/main/java/com/alibaba/cloud/examples/fallback/EchoServiceFallback.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2013-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * 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.alibaba.cloud.examples.fallback; - -import com.alibaba.cloud.examples.service.EchoService; - -/** - * @author lengleng - *

- * sentinel 降级处理 - */ -public class EchoServiceFallback implements EchoService { - - private Throwable throwable; - - EchoServiceFallback(Throwable throwable) { - this.throwable = throwable; - } - - /** - * 调用服务提供方的输出接口. - * @param str 用户输入 - * @return String - */ - @Override - public String echo(String str) { - return "consumer-fallback-default-str" + throwable.getMessage(); - } - -} diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-consumer-example/src/main/java/com/alibaba/cloud/examples/fallback/EchoServiceFallbackFactory.java b/spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-consumer-example/src/main/java/com/alibaba/cloud/examples/fallback/EchoServiceFallbackFactory.java deleted file mode 100644 index 9df335d2..00000000 --- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-consumer-example/src/main/java/com/alibaba/cloud/examples/fallback/EchoServiceFallbackFactory.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2013-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * 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.alibaba.cloud.examples.fallback; - -import feign.hystrix.FallbackFactory; - -import org.springframework.stereotype.Component; - -/** - * @author lengleng - */ -@Component -public class EchoServiceFallbackFactory implements FallbackFactory { - - @Override - public EchoServiceFallback create(Throwable throwable) { - return new EchoServiceFallback(throwable); - } - -} diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-consumer-example/src/main/java/com/alibaba/cloud/examples/service/EchoService.java b/spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-consumer-example/src/main/java/com/alibaba/cloud/examples/service/EchoService.java index 0745d15d..dbfe2312 100644 --- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-consumer-example/src/main/java/com/alibaba/cloud/examples/service/EchoService.java +++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-feign-example/sentinel-feign-consumer-example/src/main/java/com/alibaba/cloud/examples/service/EchoService.java @@ -16,8 +16,6 @@ package com.alibaba.cloud.examples.service; -import com.alibaba.cloud.examples.fallback.EchoServiceFallbackFactory; - import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -27,8 +25,7 @@ import org.springframework.web.bind.annotation.PathVariable; *

* example feign client */ -@FeignClient(name = "service-provider", - fallbackFactory = EchoServiceFallbackFactory.class) +@FeignClient(name = "service-provider") public interface EchoService { /** diff --git a/spring-cloud-alibaba-starters/spring-cloud-alibaba-sentinel-datasource/pom.xml b/spring-cloud-alibaba-starters/spring-cloud-alibaba-sentinel-datasource/pom.xml index 080a35d0..59b79118 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-alibaba-sentinel-datasource/pom.xml +++ b/spring-cloud-alibaba-starters/spring-cloud-alibaba-sentinel-datasource/pom.xml @@ -137,6 +137,12 @@ test + + junit + junit + test + + diff --git a/spring-cloud-alibaba-starters/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/zuul/SentinelZuulAutoConfiguration.java b/spring-cloud-alibaba-starters/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/zuul/SentinelZuulAutoConfiguration.java index 3f6cbd6c..6e57ae5f 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/zuul/SentinelZuulAutoConfiguration.java +++ b/spring-cloud-alibaba-starters/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/zuul/SentinelZuulAutoConfiguration.java @@ -1,102 +1,102 @@ -/* - * Copyright 2013-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * 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.alibaba.cloud.sentinel.gateway.zuul; - -import java.util.Optional; - -import javax.annotation.PostConstruct; - -import com.alibaba.cloud.sentinel.gateway.ConfigConstants; -import com.alibaba.csp.sentinel.adapter.gateway.zuul.callback.RequestOriginParser; -import com.alibaba.csp.sentinel.adapter.gateway.zuul.callback.ZuulGatewayCallbackManager; -import com.alibaba.csp.sentinel.adapter.gateway.zuul.filters.SentinelZuulErrorFilter; -import com.alibaba.csp.sentinel.adapter.gateway.zuul.filters.SentinelZuulPostFilter; -import com.alibaba.csp.sentinel.adapter.gateway.zuul.filters.SentinelZuulPreFilter; -import com.alibaba.csp.sentinel.config.SentinelConfig; -import com.netflix.zuul.http.ZuulServlet; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.support.DefaultListableBeanFactory; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -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; - -/** - * Sentinel Spring Cloud Zuul AutoConfiguration. - * - * @author tiger - */ -@Configuration(proxyBeanMethods = false) -@ConditionalOnClass(ZuulServlet.class) -@ConditionalOnProperty(prefix = ConfigConstants.ZUUL_PREFIX, name = "enabled", - havingValue = "true", matchIfMissing = true) -@EnableConfigurationProperties(SentinelZuulProperties.class) -public class SentinelZuulAutoConfiguration { - - private static final Logger logger = LoggerFactory - .getLogger(SentinelZuulAutoConfiguration.class); - - @Autowired - private Optional requestOriginParserOptional; - - @Autowired - private SentinelZuulProperties zuulProperties; - - @PostConstruct - private void init() { - requestOriginParserOptional - .ifPresent(ZuulGatewayCallbackManager::setOriginParser); - System.setProperty(SentinelConfig.APP_TYPE_PROP_KEY, - String.valueOf(ConfigConstants.APP_TYPE_ZUUL_GATEWAY)); - } - - @Bean - @ConditionalOnMissingBean - public SentinelZuulPreFilter sentinelZuulPreFilter() { - logger.info("[Sentinel Zuul] register SentinelZuulPreFilter {}", - zuulProperties.getOrder().getPre()); - return new SentinelZuulPreFilter(zuulProperties.getOrder().getPre()); - } - - @Bean - @ConditionalOnMissingBean - public SentinelZuulPostFilter sentinelZuulPostFilter() { - logger.info("[Sentinel Zuul] register SentinelZuulPostFilter {}", - zuulProperties.getOrder().getPost()); - return new SentinelZuulPostFilter(zuulProperties.getOrder().getPost()); - } - - @Bean - @ConditionalOnMissingBean - public SentinelZuulErrorFilter sentinelZuulErrorFilter() { - logger.info("[Sentinel Zuul] register SentinelZuulErrorFilter {}", - zuulProperties.getOrder().getError()); - return new SentinelZuulErrorFilter(zuulProperties.getOrder().getError()); - } - - @Bean - public FallBackProviderHandler fallBackProviderHandler( - DefaultListableBeanFactory beanFactory) { - return new FallBackProviderHandler(beanFactory); - } - -} +///* +// * Copyright 2013-2018 the original author or authors. +// * +// * Licensed under the Apache License, Version 2.0 (the "License"); +// * you may not use this file except in compliance with the License. +// * You may obtain a copy of the License at +// * +// * https://www.apache.org/licenses/LICENSE-2.0 +// * +// * 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.alibaba.cloud.sentinel.gateway.zuul; +// +//import java.util.Optional; +// +//import javax.annotation.PostConstruct; +// +//import com.alibaba.cloud.sentinel.gateway.ConfigConstants; +//import com.alibaba.csp.sentinel.adapter.gateway.zuul.callback.RequestOriginParser; +//import com.alibaba.csp.sentinel.adapter.gateway.zuul.callback.ZuulGatewayCallbackManager; +//import com.alibaba.csp.sentinel.adapter.gateway.zuul.filters.SentinelZuulErrorFilter; +//import com.alibaba.csp.sentinel.adapter.gateway.zuul.filters.SentinelZuulPostFilter; +//import com.alibaba.csp.sentinel.adapter.gateway.zuul.filters.SentinelZuulPreFilter; +//import com.alibaba.csp.sentinel.config.SentinelConfig; +//import com.netflix.zuul.http.ZuulServlet; +//import org.slf4j.Logger; +//import org.slf4j.LoggerFactory; +// +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.beans.factory.support.DefaultListableBeanFactory; +//import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +//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; +// +///** +// * Sentinel Spring Cloud Zuul AutoConfiguration. +// * +// * @author tiger +// */ +//@Configuration(proxyBeanMethods = false) +//@ConditionalOnClass(ZuulServlet.class) +//@ConditionalOnProperty(prefix = ConfigConstants.ZUUL_PREFIX, name = "enabled", +// havingValue = "true", matchIfMissing = true) +//@EnableConfigurationProperties(SentinelZuulProperties.class) +//public class SentinelZuulAutoConfiguration { +// +// private static final Logger logger = LoggerFactory +// .getLogger(SentinelZuulAutoConfiguration.class); +// +// @Autowired +// private Optional requestOriginParserOptional; +// +// @Autowired +// private SentinelZuulProperties zuulProperties; +// +// @PostConstruct +// private void init() { +// requestOriginParserOptional +// .ifPresent(ZuulGatewayCallbackManager::setOriginParser); +// System.setProperty(SentinelConfig.APP_TYPE_PROP_KEY, +// String.valueOf(ConfigConstants.APP_TYPE_ZUUL_GATEWAY)); +// } +// +// @Bean +// @ConditionalOnMissingBean +// public SentinelZuulPreFilter sentinelZuulPreFilter() { +// logger.info("[Sentinel Zuul] register SentinelZuulPreFilter {}", +// zuulProperties.getOrder().getPre()); +// return new SentinelZuulPreFilter(zuulProperties.getOrder().getPre()); +// } +// +// @Bean +// @ConditionalOnMissingBean +// public SentinelZuulPostFilter sentinelZuulPostFilter() { +// logger.info("[Sentinel Zuul] register SentinelZuulPostFilter {}", +// zuulProperties.getOrder().getPost()); +// return new SentinelZuulPostFilter(zuulProperties.getOrder().getPost()); +// } +// +// @Bean +// @ConditionalOnMissingBean +// public SentinelZuulErrorFilter sentinelZuulErrorFilter() { +// logger.info("[Sentinel Zuul] register SentinelZuulErrorFilter {}", +// zuulProperties.getOrder().getError()); +// return new SentinelZuulErrorFilter(zuulProperties.getOrder().getError()); +// } +// +// @Bean +// public FallBackProviderHandler fallBackProviderHandler( +// DefaultListableBeanFactory beanFactory) { +// return new FallBackProviderHandler(beanFactory); +// } +// +//} diff --git a/spring-cloud-alibaba-starters/spring-cloud-alibaba-sentinel-gateway/src/main/resources/META-INF/spring.factories b/spring-cloud-alibaba-starters/spring-cloud-alibaba-sentinel-gateway/src/main/resources/META-INF/spring.factories index 1cb4c57b..eb9e6831 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-alibaba-sentinel-gateway/src/main/resources/META-INF/spring.factories +++ b/spring-cloud-alibaba-starters/spring-cloud-alibaba-sentinel-gateway/src/main/resources/META-INF/spring.factories @@ -1,5 +1,4 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -com.alibaba.cloud.sentinel.gateway.zuul.SentinelZuulAutoConfiguration,\ com.alibaba.cloud.sentinel.gateway.scg.SentinelSCGAutoConfiguration,\ com.alibaba.cloud.sentinel.gateway.SentinelGatewayAutoConfiguration org.springframework.boot.env.EnvironmentPostProcessor=com.alibaba.cloud.sentinel.gateway.GatewayEnvironmentPostProcessor \ No newline at end of file diff --git a/spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/pom.xml b/spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/pom.xml index 90f0f0ff..c110ceff 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/pom.xml +++ b/spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/pom.xml @@ -62,6 +62,12 @@ test + + junit + junit + test + + diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/ConditionalOnRibbonNacos.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/ConditionalOnRibbonNacos.java deleted file mode 100644 index 1cbdb659..00000000 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/ConditionalOnRibbonNacos.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2013-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * 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.alibaba.cloud.nacos.ribbon; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; - -@Retention(RetentionPolicy.RUNTIME) -@Target({ ElementType.TYPE, ElementType.METHOD }) -@ConditionalOnProperty(value = "ribbon.nacos.enabled", matchIfMissing = true) -public @interface ConditionalOnRibbonNacos { - -} diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/ExtendBalancer.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/ExtendBalancer.java deleted file mode 100644 index e52278cb..00000000 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/ExtendBalancer.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2013-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * 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.alibaba.cloud.nacos.ribbon; - -import java.util.List; - -import com.alibaba.nacos.api.naming.pojo.Instance; -import com.alibaba.nacos.client.naming.core.Balancer; - -/** - * @author itmuch.com - */ -public class ExtendBalancer extends Balancer { - - /** - * Choose instance by weight. - * @param instances Instance List - * @return the chosen instance - */ - public static Instance getHostByRandomWeight2(List instances) { - return getHostByRandomWeight(instances); - } - -} diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/NacosRibbonClientConfiguration.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/NacosRibbonClientConfiguration.java deleted file mode 100644 index a6294e87..00000000 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/NacosRibbonClientConfiguration.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2013-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * 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.alibaba.cloud.nacos.ribbon; - -import com.alibaba.cloud.nacos.NacosDiscoveryProperties; -import com.netflix.client.config.IClientConfig; -import com.netflix.loadbalancer.ServerList; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.cloud.netflix.ribbon.PropertiesFactory; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * integrated Ribbon by default. - * - * @author xiaojing - * @author liujunjie - */ -@Configuration(proxyBeanMethods = false) -@ConditionalOnRibbonNacos -public class NacosRibbonClientConfiguration { - - @Autowired - private PropertiesFactory propertiesFactory; - - @Bean - @ConditionalOnMissingBean - public ServerList ribbonServerList(IClientConfig config, - NacosDiscoveryProperties nacosDiscoveryProperties) { - if (this.propertiesFactory.isSet(ServerList.class, config.getClientName())) { - ServerList serverList = this.propertiesFactory.get(ServerList.class, config, - config.getClientName()); - return serverList; - } - NacosServerList serverList = new NacosServerList(nacosDiscoveryProperties); - serverList.initWithNiwsConfig(config); - return serverList; - } - - @Bean - @ConditionalOnMissingBean - public NacosServerIntrospector nacosServerIntrospector() { - return new NacosServerIntrospector(); - } - -} diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/NacosRule.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/NacosRule.java deleted file mode 100644 index 9873b8db..00000000 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/NacosRule.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright 2013-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * 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.alibaba.cloud.nacos.ribbon; - -import java.util.List; -import java.util.Objects; -import java.util.stream.Collectors; - -import com.alibaba.cloud.commons.lang.StringUtils; -import com.alibaba.cloud.nacos.NacosDiscoveryProperties; -import com.alibaba.cloud.nacos.NacosServiceManager; -import com.alibaba.nacos.api.naming.NamingService; -import com.alibaba.nacos.api.naming.pojo.Instance; -import com.netflix.client.config.IClientConfig; -import com.netflix.loadbalancer.AbstractLoadBalancerRule; -import com.netflix.loadbalancer.DynamicServerListLoadBalancer; -import com.netflix.loadbalancer.Server; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; - -/** - * Supports preferentially calling the ribbon load balancing rules of the same cluster - * instance. - * - * @author itmuch.com - */ -public class NacosRule extends AbstractLoadBalancerRule { - - private static final Logger LOGGER = LoggerFactory.getLogger(NacosRule.class); - - @Autowired - private NacosDiscoveryProperties nacosDiscoveryProperties; - - @Autowired - private NacosServiceManager nacosServiceManager; - - @Override - public Server choose(Object key) { - try { - String clusterName = this.nacosDiscoveryProperties.getClusterName(); - String group = this.nacosDiscoveryProperties.getGroup(); - DynamicServerListLoadBalancer loadBalancer = (DynamicServerListLoadBalancer) getLoadBalancer(); - String name = loadBalancer.getName(); - - NamingService namingService = nacosServiceManager - .getNamingService(nacosDiscoveryProperties.getNacosProperties()); - List instances = namingService.selectInstances(name, group, true); - if (CollectionUtils.isEmpty(instances)) { - LOGGER.warn("no instance in service {}", name); - return null; - } - - List instancesToChoose = instances; - if (StringUtils.isNotBlank(clusterName)) { - List sameClusterInstances = instances.stream() - .filter(instance -> Objects.equals(clusterName, - instance.getClusterName())) - .collect(Collectors.toList()); - if (!CollectionUtils.isEmpty(sameClusterInstances)) { - instancesToChoose = sameClusterInstances; - } - else { - LOGGER.warn( - "A cross-cluster call occurs,name = {}, clusterName = {}, instance = {}", - name, clusterName, instances); - } - } - - Instance instance = ExtendBalancer.getHostByRandomWeight2(instancesToChoose); - - return new NacosServer(instance); - } - catch (Exception e) { - LOGGER.warn("NacosRule error", e); - return null; - } - } - - @Override - public void initWithNiwsConfig(IClientConfig iClientConfig) { - } - -} diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/NacosServer.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/NacosServer.java deleted file mode 100644 index 9c292a9a..00000000 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/NacosServer.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2013-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * 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.alibaba.cloud.nacos.ribbon; - -import java.util.Map; - -import com.alibaba.nacos.api.naming.pojo.Instance; -import com.netflix.loadbalancer.Server; - -/** - * @author xiaojing - * @author pbting - */ -public class NacosServer extends Server { - - private final MetaInfo metaInfo; - - private final Instance instance; - - private final Map metadata; - - public NacosServer(final Instance instance) { - super(instance.getIp(), instance.getPort()); - this.instance = instance; - this.metaInfo = new MetaInfo() { - @Override - public String getAppName() { - return instance.getServiceName(); - } - - @Override - public String getServerGroup() { - return null; - } - - @Override - public String getServiceIdForDiscovery() { - return null; - } - - @Override - public String getInstanceId() { - return instance.getInstanceId(); - } - }; - this.metadata = instance.getMetadata(); - } - - @Override - public MetaInfo getMetaInfo() { - return metaInfo; - } - - public Instance getInstance() { - return instance; - } - - public Map getMetadata() { - return metadata; - } - -} diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/NacosServerIntrospector.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/NacosServerIntrospector.java deleted file mode 100644 index d186446d..00000000 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/NacosServerIntrospector.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2013-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * 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.alibaba.cloud.nacos.ribbon; - -import java.util.Map; - -import com.netflix.loadbalancer.Server; - -import org.springframework.cloud.netflix.ribbon.DefaultServerIntrospector; - -/** - * @author xiaojing - */ -public class NacosServerIntrospector extends DefaultServerIntrospector { - - @Override - public Map getMetadata(Server server) { - if (server instanceof NacosServer) { - return ((NacosServer) server).getMetadata(); - } - return super.getMetadata(server); - } - - @Override - public boolean isSecure(Server server) { - if (server instanceof NacosServer) { - return Boolean.valueOf(((NacosServer) server).getMetadata().get("secure")); - } - - return super.isSecure(server); - } - -} diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/NacosServerList.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/NacosServerList.java deleted file mode 100644 index 55928f26..00000000 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/NacosServerList.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2013-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * 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.alibaba.cloud.nacos.ribbon; - -import java.util.ArrayList; -import java.util.List; - -import com.alibaba.cloud.nacos.NacosDiscoveryProperties; -import com.alibaba.nacos.api.naming.pojo.Instance; -import com.alibaba.nacos.client.naming.utils.CollectionUtils; -import com.netflix.client.config.IClientConfig; -import com.netflix.loadbalancer.AbstractServerList; - -/** - * @author xiaojing - * @author renhaojun - */ -public class NacosServerList extends AbstractServerList { - - private NacosDiscoveryProperties discoveryProperties; - - private String serviceId; - - public NacosServerList(NacosDiscoveryProperties discoveryProperties) { - this.discoveryProperties = discoveryProperties; - } - - @Override - public List getInitialListOfServers() { - return getServers(); - } - - @Override - public List getUpdatedListOfServers() { - return getServers(); - } - - private List getServers() { - try { - String group = discoveryProperties.getGroup(); - List instances = discoveryProperties.namingServiceInstance() - .selectInstances(serviceId, group, true); - return instancesToServerList(instances); - } - catch (Exception e) { - throw new IllegalStateException( - "Can not get service instances from nacos, serviceId=" + serviceId, - e); - } - } - - private List instancesToServerList(List instances) { - List result = new ArrayList<>(); - if (CollectionUtils.isEmpty(instances)) { - return result; - } - for (Instance instance : instances) { - result.add(new NacosServer(instance)); - } - - return result; - } - - public String getServiceId() { - return serviceId; - } - - @Override - public void initWithNiwsConfig(IClientConfig iClientConfig) { - this.serviceId = iClientConfig.getClientName(); - } - -} diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/RibbonNacosAutoConfiguration.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/RibbonNacosAutoConfiguration.java deleted file mode 100644 index 4b504d3a..00000000 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/ribbon/RibbonNacosAutoConfiguration.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2013-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * 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.alibaba.cloud.nacos.ribbon; - -import com.alibaba.cloud.nacos.ConditionalOnNacosDiscoveryEnabled; - -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.cloud.netflix.ribbon.RibbonAutoConfiguration; -import org.springframework.cloud.netflix.ribbon.RibbonClients; -import org.springframework.cloud.netflix.ribbon.SpringClientFactory; -import org.springframework.context.annotation.Configuration; - -/** - * {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration - * Auto-configuration} that sets up Ribbon for Nacos. - */ -@Configuration(proxyBeanMethods = false) -@EnableConfigurationProperties -@ConditionalOnBean(SpringClientFactory.class) -@ConditionalOnRibbonNacos -@ConditionalOnNacosDiscoveryEnabled -@AutoConfigureAfter(RibbonAutoConfiguration.class) -@RibbonClients(defaultConfiguration = NacosRibbonClientConfiguration.class) -public class RibbonNacosAutoConfiguration { - -} diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/resources/META-INF/spring.factories b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/resources/META-INF/spring.factories index 80befe75..48ae045e 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/resources/META-INF/spring.factories +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/resources/META-INF/spring.factories @@ -1,6 +1,5 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ com.alibaba.cloud.nacos.discovery.NacosDiscoveryAutoConfiguration,\ - com.alibaba.cloud.nacos.ribbon.RibbonNacosAutoConfiguration,\ com.alibaba.cloud.nacos.endpoint.NacosDiscoveryEndpointAutoConfiguration,\ com.alibaba.cloud.nacos.registry.NacosServiceRegistryAutoConfiguration,\ com.alibaba.cloud.nacos.discovery.NacosDiscoveryClientConfiguration,\ diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/ribbon/NacosRibbonClientConfigurationTests.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/ribbon/NacosRibbonClientConfigurationTests.java deleted file mode 100644 index 0256f4fb..00000000 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/ribbon/NacosRibbonClientConfigurationTests.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2013-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * 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.alibaba.cloud.nacos.ribbon; - -import com.alibaba.cloud.nacos.discovery.NacosDiscoveryClientConfiguration; -import com.netflix.client.config.DefaultClientConfigImpl; -import com.netflix.client.config.IClientConfig; -import org.junit.Test; - -import org.springframework.boot.autoconfigure.AutoConfigurations; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.test.context.runner.WebApplicationContextRunner; -import org.springframework.cloud.client.discovery.EnableDiscoveryClient; -import org.springframework.cloud.client.loadbalancer.LoadBalanced; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.client.RestTemplate; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * @author xiaojing - */ -public class NacosRibbonClientConfigurationTests { - - private WebApplicationContextRunner contextRunner = new WebApplicationContextRunner() - .withConfiguration(AutoConfigurations.of(NacosRibbonTestConfiguration.class, - NacosRibbonClientConfiguration.class, - NacosDiscoveryClientConfiguration.class, - RibbonNacosAutoConfiguration.class)) - .withPropertyValues("spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848") - .withPropertyValues("spring.cloud.nacos.discovery.port=18080") - .withPropertyValues("spring.cloud.nacos.discovery.service=myapp"); - - @Test - public void testProperties() { - - this.contextRunner.run(context -> { - NacosServerList serverList = context.getBean(NacosServerList.class); - assertThat(serverList.getServiceId()).isEqualTo("myapp"); - }); - } - - @Configuration - @EnableAutoConfiguration - @EnableDiscoveryClient - static class NacosRibbonTestConfiguration { - - @Bean - IClientConfig iClientConfig() { - DefaultClientConfigImpl config = new DefaultClientConfigImpl(); - config.setClientName("myapp"); - return config; - } - - @Bean - @LoadBalanced - RestTemplate restTemplate() { - return new RestTemplate(); - } - - } - -} diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/ribbon/NacosRibbonClientPropertyOverrideTests.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/ribbon/NacosRibbonClientPropertyOverrideTests.java deleted file mode 100644 index 3692414f..00000000 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/ribbon/NacosRibbonClientPropertyOverrideTests.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2013-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * 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.alibaba.cloud.nacos.ribbon; - -import com.alibaba.cloud.nacos.discovery.NacosDiscoveryClientConfiguration; -import com.netflix.loadbalancer.ConfigurationBasedServerList; -import com.netflix.loadbalancer.Server; -import com.netflix.loadbalancer.ZoneAwareLoadBalancer; -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.ImportAutoConfiguration; -import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.cloud.commons.util.UtilAutoConfiguration; -import org.springframework.cloud.netflix.archaius.ArchaiusAutoConfiguration; -import org.springframework.cloud.netflix.ribbon.RibbonClients; -import org.springframework.cloud.netflix.ribbon.SpringClientFactory; -import org.springframework.context.annotation.Configuration; -import org.springframework.test.context.junit4.SpringRunner; - -/** - * @author liujunjie - */ -@RunWith(SpringRunner.class) -@SpringBootTest(classes = NacosRibbonClientPropertyOverrideTests.TestConfiguration.class, - properties = { "spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848", - "spring.cloud.nacos.discovery.port=18080", - "spring.cloud.nacos.discovery.service=remoteApp", - "localApp.ribbon.NIWSServerListClassName=" - + "com.netflix.loadbalancer.ConfigurationBasedServerList", - "localApp.ribbon.listOfServers=127.0.0.1:19090", - "localApp.ribbon.ServerListRefreshInterval=15000" }) -public class NacosRibbonClientPropertyOverrideTests { - - @Autowired - private SpringClientFactory factory; - - @Test - public void serverListOverridesToTest() { - ConfigurationBasedServerList.class - .cast(getLoadBalancer("localApp").getServerListImpl()); - } - - @Test - public void serverListRemoteTest() { - NacosServerList.class.cast(getLoadBalancer("remoteApp").getServerListImpl()); - } - - @SuppressWarnings("unchecked") - private ZoneAwareLoadBalancer getLoadBalancer(String name) { - return (ZoneAwareLoadBalancer) this.factory.getLoadBalancer(name); - } - - @Configuration - @RibbonClients - @EnableAutoConfiguration - @ImportAutoConfiguration({ UtilAutoConfiguration.class, - PropertyPlaceholderAutoConfiguration.class, ArchaiusAutoConfiguration.class, - RibbonNacosAutoConfiguration.class, NacosDiscoveryClientConfiguration.class }) - protected static class TestConfiguration { - - } - -} diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/ribbon/NacosServerListTests.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/ribbon/NacosServerListTests.java deleted file mode 100644 index 1c6e65d9..00000000 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/ribbon/NacosServerListTests.java +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Copyright 2013-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * 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.alibaba.cloud.nacos.ribbon; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.stream.Collectors; - -import com.alibaba.cloud.nacos.NacosDiscoveryProperties; -import com.alibaba.cloud.nacos.test.NacosMockTest; -import com.alibaba.nacos.api.naming.NamingService; -import com.alibaba.nacos.api.naming.pojo.Instance; -import com.netflix.client.config.IClientConfig; -import org.junit.Test; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -/** - * @author xiaojing - */ - -public class NacosServerListTests { - - @Test - @SuppressWarnings("unchecked") - public void testEmptyInstancesReturnsEmptyList() throws Exception { - NacosDiscoveryProperties nacosDiscoveryProperties = mock( - NacosDiscoveryProperties.class); - - NamingService namingService = mock(NamingService.class); - - when(nacosDiscoveryProperties.namingServiceInstance()).thenReturn(namingService); - when(namingService.selectInstances(anyString(), eq("DEFAULT"), eq(true))) - .thenReturn(null); - - NacosServerList serverList = new NacosServerList(nacosDiscoveryProperties); - List servers = serverList.getInitialListOfServers(); - assertThat(servers).isEmpty(); - } - - @Test - @SuppressWarnings("unchecked") - public void testGetServers() throws Exception { - - ArrayList instances = new ArrayList<>(); - instances.add(NacosMockTest.serviceInstance("test-service", false, - Collections.emptyMap())); - - NacosDiscoveryProperties nacosDiscoveryProperties = mock( - NacosDiscoveryProperties.class); - - NamingService namingService = mock(NamingService.class); - - when(nacosDiscoveryProperties.namingServiceInstance()).thenReturn(namingService); - when(nacosDiscoveryProperties.getGroup()).thenReturn("DEFAULT"); - when(nacosDiscoveryProperties.getGroup()).thenReturn("DEFAULT"); - when(namingService.selectInstances(eq("test-service"), eq("DEFAULT"), eq(true))) - .thenReturn(instances); - - IClientConfig clientConfig = mock(IClientConfig.class); - when(clientConfig.getClientName()).thenReturn("test-service"); - NacosServerList serverList = new NacosServerList(nacosDiscoveryProperties); - serverList.initWithNiwsConfig(clientConfig); - List servers = serverList.getInitialListOfServers(); - assertThat(servers).hasSize(1); - - servers = serverList.getUpdatedListOfServers(); - assertThat(servers).hasSize(1); - } - - @Test - @SuppressWarnings("unchecked") - public void testGetServersWithInstanceStatus() throws Exception { - ArrayList instances = new ArrayList<>(); - - HashMap map1 = new HashMap<>(); - map1.put("instanceNum", "1"); - HashMap map2 = new HashMap<>(); - map2.put("instanceNum", "2"); - instances.add(NacosMockTest.serviceInstance("test-service", false, map1)); - instances.add(NacosMockTest.serviceInstance("test-service", true, map2)); - - NacosDiscoveryProperties nacosDiscoveryProperties = mock( - NacosDiscoveryProperties.class); - - NamingService namingService = mock(NamingService.class); - - when(nacosDiscoveryProperties.namingServiceInstance()).thenReturn(namingService); - when(nacosDiscoveryProperties.getGroup()).thenReturn("DEFAULT"); - when(namingService.selectInstances(eq("test-service"), eq("DEFAULT"), eq(true))) - .thenReturn(instances.stream().filter(Instance::isHealthy) - .collect(Collectors.toList())); - - IClientConfig clientConfig = mock(IClientConfig.class); - when(clientConfig.getClientName()).thenReturn("test-service"); - NacosServerList serverList = new NacosServerList(nacosDiscoveryProperties); - serverList.initWithNiwsConfig(clientConfig); - List servers = serverList.getInitialListOfServers(); - assertThat(servers).hasSize(1); - - NacosServer nacosServer = servers.get(0); - - assertThat(nacosServer.getMetaInfo().getInstanceId()) - .isEqualTo(instances.get(1).getInstanceId()); - assertThat(nacosServer.getMetadata()).isEqualTo(map2); - assertThat(nacosServer.getInstance().isHealthy()).isEqualTo(true); - assertThat(nacosServer.getInstance().getServiceName()).isEqualTo("test-service"); - assertThat(nacosServer.getInstance().getMetadata().get("instanceNum")) - .isEqualTo("2"); - - } - - @Test - public void testUpdateServers() throws Exception { - ArrayList instances = new ArrayList<>(); - - HashMap map = new HashMap<>(); - map.put("instanceNum", "1"); - instances.add(NacosMockTest.serviceInstance("test-service", true, map)); - - NacosDiscoveryProperties nacosDiscoveryProperties = mock( - NacosDiscoveryProperties.class); - - NamingService namingService = mock(NamingService.class); - - when(nacosDiscoveryProperties.namingServiceInstance()).thenReturn(namingService); - when(nacosDiscoveryProperties.getGroup()).thenReturn("DEFAULT"); - when(namingService.selectInstances(eq("test-service"), eq("DEFAULT"), eq(true))) - .thenReturn(instances.stream().filter(Instance::isHealthy) - .collect(Collectors.toList())); - - IClientConfig clientConfig = mock(IClientConfig.class); - when(clientConfig.getClientName()).thenReturn("test-service"); - NacosServerList serverList = new NacosServerList(nacosDiscoveryProperties); - serverList.initWithNiwsConfig(clientConfig); - - List servers = serverList.getUpdatedListOfServers(); - assertThat(servers).hasSize(1); - - assertThat(servers.get(0).getInstance().isHealthy()).isEqualTo(true); - assertThat(servers.get(0).getInstance().getMetadata().get("instanceNum")) - .isEqualTo("1"); - } - -} diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignBlockingLoadBalancerClient.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignBlockingLoadBalancerClient.java index b504ccc8..74152e62 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignBlockingLoadBalancerClient.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignBlockingLoadBalancerClient.java @@ -22,7 +22,9 @@ import feign.Client; import feign.Request; import feign.Response; +import org.springframework.cloud.client.loadbalancer.LoadBalancerProperties; import org.springframework.cloud.loadbalancer.blocking.client.BlockingLoadBalancerClient; +import org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory; import org.springframework.cloud.openfeign.loadbalancer.FeignBlockingLoadBalancerClient; /** @@ -32,9 +34,11 @@ public class SeataFeignBlockingLoadBalancerClient extends FeignBlockingLoadBalancerClient { public SeataFeignBlockingLoadBalancerClient(Client delegate, - BlockingLoadBalancerClient loadBalancerClient, - SeataFeignObjectWrapper seataFeignObjectWrapper) { - super((Client) seataFeignObjectWrapper.wrap(delegate), loadBalancerClient); + BlockingLoadBalancerClient loadBalancerClient, + LoadBalancerProperties properties, + LoadBalancerClientFactory loadBalancerClientFactory, + SeataFeignObjectWrapper seataFeignObjectWrapper) { + super((Client) seataFeignObjectWrapper.wrap(delegate), loadBalancerClient, properties, loadBalancerClientFactory); } @Override diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignClientAutoConfiguration.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignClientAutoConfiguration.java index 55bbb60c..50659e80 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignClientAutoConfiguration.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignClientAutoConfiguration.java @@ -38,13 +38,13 @@ import org.springframework.context.annotation.Scope; @AutoConfigureBefore(FeignAutoConfiguration.class) public class SeataFeignClientAutoConfiguration { - @Bean - @Scope("prototype") - @ConditionalOnClass(name = "com.netflix.hystrix.HystrixCommand") - @ConditionalOnProperty(name = "feign.hystrix.enabled", havingValue = "true") - Feign.Builder feignHystrixBuilder(BeanFactory beanFactory) { - return SeataHystrixFeignBuilder.builder(beanFactory); - } +// @Bean +// @Scope("prototype") +// @ConditionalOnClass(name = "com.netflix.hystrix.HystrixCommand") +// @ConditionalOnProperty(name = "feign.hystrix.enabled", havingValue = "true") +// Feign.Builder feignHystrixBuilder(BeanFactory beanFactory) { +// return SeataHystrixFeignBuilder.builder(beanFactory); +// } @Bean @Scope("prototype") diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignObjectWrapper.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignObjectWrapper.java index c13391db..b7b4deca 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignObjectWrapper.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignObjectWrapper.java @@ -21,11 +21,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.BeanFactory; +import org.springframework.cloud.client.loadbalancer.LoadBalancerProperties; import org.springframework.cloud.loadbalancer.blocking.client.BlockingLoadBalancerClient; -import org.springframework.cloud.netflix.ribbon.SpringClientFactory; +import org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory; +//import org.springframework.cloud.netflix.ribbon.SpringClientFactory; import org.springframework.cloud.openfeign.loadbalancer.FeignBlockingLoadBalancerClient; -import org.springframework.cloud.openfeign.ribbon.CachingSpringLoadBalancerFactory; -import org.springframework.cloud.openfeign.ribbon.LoadBalancerFeignClient; +//import org.springframework.cloud.openfeign.ribbon.CachingSpringLoadBalancerFactory; +//import org.springframework.cloud.openfeign.ribbon.LoadBalancerFeignClient; /** * @author xiaojing @@ -37,9 +39,9 @@ public class SeataFeignObjectWrapper { private final BeanFactory beanFactory; - private CachingSpringLoadBalancerFactory cachingSpringLoadBalancerFactory; +// private CachingSpringLoadBalancerFactory cachingSpringLoadBalancerFactory; - private SpringClientFactory springClientFactory; +// private SpringClientFactory springClientFactory; SeataFeignObjectWrapper(BeanFactory beanFactory) { this.beanFactory = beanFactory; @@ -47,35 +49,38 @@ public class SeataFeignObjectWrapper { Object wrap(Object bean) { if (bean instanceof Client && !(bean instanceof SeataFeignClient)) { - if (bean instanceof LoadBalancerFeignClient) { - LoadBalancerFeignClient client = ((LoadBalancerFeignClient) bean); - return new SeataLoadBalancerFeignClient(client.getDelegate(), factory(), - clientFactory(), this); - } +// if (bean instanceof LoadBalancerFeignClient) { +// LoadBalancerFeignClient client = ((LoadBalancerFeignClient) bean); +// return new SeataLoadBalancerFeignClient(client.getDelegate(), factory(), +// clientFactory(), this); +// } if (bean instanceof FeignBlockingLoadBalancerClient) { FeignBlockingLoadBalancerClient client = (FeignBlockingLoadBalancerClient) bean; return new SeataFeignBlockingLoadBalancerClient(client.getDelegate(), - beanFactory.getBean(BlockingLoadBalancerClient.class), this); + beanFactory.getBean(BlockingLoadBalancerClient.class), + beanFactory.getBean(LoadBalancerProperties.class), + beanFactory.getBean(LoadBalancerClientFactory.class), + this); } return new SeataFeignClient(this.beanFactory, (Client) bean); } return bean; } - CachingSpringLoadBalancerFactory factory() { - if (this.cachingSpringLoadBalancerFactory == null) { - this.cachingSpringLoadBalancerFactory = this.beanFactory - .getBean(CachingSpringLoadBalancerFactory.class); - } - return this.cachingSpringLoadBalancerFactory; - } +// CachingSpringLoadBalancerFactory factory() { +// if (this.cachingSpringLoadBalancerFactory == null) { +// this.cachingSpringLoadBalancerFactory = this.beanFactory +// .getBean(CachingSpringLoadBalancerFactory.class); +// } +// return this.cachingSpringLoadBalancerFactory; +// } - SpringClientFactory clientFactory() { - if (this.springClientFactory == null) { - this.springClientFactory = this.beanFactory - .getBean(SpringClientFactory.class); - } - return this.springClientFactory; - } +// SpringClientFactory clientFactory() { +// if (this.springClientFactory == null) { +// this.springClientFactory = this.beanFactory +// .getBean(SpringClientFactory.class); +// } +// return this.springClientFactory; +// } } diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataHystrixFeignBuilder.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataHystrixFeignBuilder.java index 98fb605f..c5b48e5a 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataHystrixFeignBuilder.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataHystrixFeignBuilder.java @@ -1,38 +1,38 @@ -/* - * Copyright 2013-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * 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.alibaba.cloud.seata.feign; - -import feign.Feign; -import feign.Retryer; -import feign.hystrix.HystrixFeign; - -import org.springframework.beans.factory.BeanFactory; - -/** - * @author xiaojing - */ -final class SeataHystrixFeignBuilder { - - private SeataHystrixFeignBuilder() { - } - - static Feign.Builder builder(BeanFactory beanFactory) { - return HystrixFeign.builder().retryer(Retryer.NEVER_RETRY) - .client(new SeataFeignClient(beanFactory)); - } - -} +///* +// * Copyright 2013-2018 the original author or authors. +// * +// * Licensed under the Apache License, Version 2.0 (the "License"); +// * you may not use this file except in compliance with the License. +// * You may obtain a copy of the License at +// * +// * https://www.apache.org/licenses/LICENSE-2.0 +// * +// * 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.alibaba.cloud.seata.feign; +// +//import feign.Feign; +//import feign.Retryer; +//import feign.hystrix.HystrixFeign; +// +//import org.springframework.beans.factory.BeanFactory; +// +///** +// * @author xiaojing +// */ +//final class SeataHystrixFeignBuilder { +// +// private SeataHystrixFeignBuilder() { +// } +// +// static Feign.Builder builder(BeanFactory beanFactory) { +// return HystrixFeign.builder().retryer(Retryer.NEVER_RETRY) +// .client(new SeataFeignClient(beanFactory)); +// } +// +//} diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataLoadBalancerFeignClient.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataLoadBalancerFeignClient.java index 8204fed8..e6525d01 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataLoadBalancerFeignClient.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataLoadBalancerFeignClient.java @@ -1,48 +1,45 @@ -/* - * Copyright 2013-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * 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.alibaba.cloud.seata.feign; - -import java.io.IOException; - -import feign.Client; -import feign.Request; -import feign.Response; - -import org.springframework.cloud.netflix.ribbon.SpringClientFactory; -import org.springframework.cloud.openfeign.ribbon.CachingSpringLoadBalancerFactory; -import org.springframework.cloud.openfeign.ribbon.LoadBalancerFeignClient; - -/** - * @author xiaojing - * @author yuhuangbin - */ -public class SeataLoadBalancerFeignClient extends LoadBalancerFeignClient { - - SeataLoadBalancerFeignClient(Client delegate, - CachingSpringLoadBalancerFactory lbClientFactory, - SpringClientFactory clientFactory, - SeataFeignObjectWrapper seataFeignObjectWrapper) { - super((Client) seataFeignObjectWrapper.wrap(delegate), lbClientFactory, - clientFactory); - } - - @Override - public Response execute(Request request, Request.Options options) throws IOException { - return super.execute(request, options); - } - -} +///* +// * Copyright 2013-2018 the original author or authors. +// * +// * Licensed under the Apache License, Version 2.0 (the "License"); +// * you may not use this file except in compliance with the License. +// * You may obtain a copy of the License at +// * +// * https://www.apache.org/licenses/LICENSE-2.0 +// * +// * 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.alibaba.cloud.seata.feign; +// +//import java.io.IOException; +// +//import feign.Client; +//import feign.Request; +//import feign.Response; +// +// +///** +// * @author xiaojing +// * @author yuhuangbin +// */ +//public class SeataLoadBalancerFeignClient extends LoadBalancerFeignClient { +// +// SeataLoadBalancerFeignClient(Client delegate, +// CachingSpringLoadBalancerFactory lbClientFactory, +// SpringClientFactory clientFactory, +// SeataFeignObjectWrapper seataFeignObjectWrapper) { +// super((Client) seataFeignObjectWrapper.wrap(delegate), lbClientFactory, +// clientFactory); +// } +// +// @Override +// public Response execute(Request request, Request.Options options) throws IOException { +// return super.execute(request, options); +// } +// +//} diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/hystrix/SeataHystrixAutoConfiguration.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/hystrix/SeataHystrixAutoConfiguration.java deleted file mode 100644 index a790c9d2..00000000 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/hystrix/SeataHystrixAutoConfiguration.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2013-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * 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.alibaba.cloud.seata.feign.hystrix; - -import com.netflix.hystrix.HystrixCommand; - -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * @author xiaojing - */ -@Configuration(proxyBeanMethods = false) -@ConditionalOnClass(HystrixCommand.class) -public class SeataHystrixAutoConfiguration { - - @Bean - SeataHystrixConcurrencyStrategy seataHystrixConcurrencyStrategy() { - return new SeataHystrixConcurrencyStrategy(); - } - -} diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/hystrix/SeataHystrixConcurrencyStrategy.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/hystrix/SeataHystrixConcurrencyStrategy.java deleted file mode 100644 index d0a1528b..00000000 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/hystrix/SeataHystrixConcurrencyStrategy.java +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Copyright 2013-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * 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.alibaba.cloud.seata.feign.hystrix; - -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.Callable; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; - -import com.netflix.hystrix.HystrixThreadPoolKey; -import com.netflix.hystrix.HystrixThreadPoolProperties; -import com.netflix.hystrix.strategy.HystrixPlugins; -import com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy; -import com.netflix.hystrix.strategy.concurrency.HystrixRequestVariable; -import com.netflix.hystrix.strategy.concurrency.HystrixRequestVariableLifecycle; -import com.netflix.hystrix.strategy.eventnotifier.HystrixEventNotifier; -import com.netflix.hystrix.strategy.executionhook.HystrixCommandExecutionHook; -import com.netflix.hystrix.strategy.metrics.HystrixMetricsPublisher; -import com.netflix.hystrix.strategy.properties.HystrixPropertiesStrategy; -import com.netflix.hystrix.strategy.properties.HystrixProperty; -import io.seata.core.context.RootContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.springframework.util.StringUtils; -import org.springframework.web.context.request.RequestAttributes; -import org.springframework.web.context.request.RequestContextHolder; - -/** - * @author xiaojing - */ -public class SeataHystrixConcurrencyStrategy extends HystrixConcurrencyStrategy { - - private final Logger logger = LoggerFactory - .getLogger(SeataHystrixConcurrencyStrategy.class); - - private HystrixConcurrencyStrategy delegate; - - public SeataHystrixConcurrencyStrategy() { - try { - this.delegate = HystrixPlugins.getInstance().getConcurrencyStrategy(); - if (this.delegate instanceof SeataHystrixConcurrencyStrategy) { - return; - } - HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins - .getInstance().getCommandExecutionHook(); - HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance() - .getEventNotifier(); - HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance() - .getMetricsPublisher(); - HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance() - .getPropertiesStrategy(); - logCurrentStateOfHystrixPlugins(eventNotifier, metricsPublisher, - propertiesStrategy); - HystrixPlugins.reset(); - HystrixPlugins.getInstance().registerConcurrencyStrategy(this); - HystrixPlugins.getInstance() - .registerCommandExecutionHook(commandExecutionHook); - HystrixPlugins.getInstance().registerEventNotifier(eventNotifier); - HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher); - HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy); - } - catch (Exception ex) { - logger.error("Failed to register Seata Hystrix Concurrency Strategy", ex); - } - } - - private void logCurrentStateOfHystrixPlugins(HystrixEventNotifier eventNotifier, - HystrixMetricsPublisher metricsPublisher, - HystrixPropertiesStrategy propertiesStrategy) { - if (logger.isDebugEnabled()) { - logger.debug("Current Hystrix plugins configuration is [" - + "concurrencyStrategy [" + this.delegate + "]," + "eventNotifier [" - + eventNotifier + "]," + "metricPublisher [" + metricsPublisher + "]," - + "propertiesStrategy [" + propertiesStrategy + "]," + "]"); - logger.debug("Registering Seata Hystrix Concurrency Strategy."); - } - } - - @Override - public ThreadPoolExecutor getThreadPool(HystrixThreadPoolKey threadPoolKey, - HystrixProperty corePoolSize, - HystrixProperty maximumPoolSize, - HystrixProperty keepAliveTime, TimeUnit unit, - BlockingQueue workQueue) { - return this.delegate.getThreadPool(threadPoolKey, corePoolSize, maximumPoolSize, - keepAliveTime, unit, workQueue); - } - - @Override - public ThreadPoolExecutor getThreadPool(HystrixThreadPoolKey threadPoolKey, - HystrixThreadPoolProperties threadPoolProperties) { - return this.delegate.getThreadPool(threadPoolKey, threadPoolProperties); - } - - @Override - public BlockingQueue getBlockingQueue(int maxQueueSize) { - return this.delegate.getBlockingQueue(maxQueueSize); - } - - @Override - public HystrixRequestVariable getRequestVariable( - HystrixRequestVariableLifecycle rv) { - return this.delegate.getRequestVariable(rv); - } - - @Override - public Callable wrapCallable(Callable c) { - if (c instanceof SeataContextCallable) { - return c; - } - - Callable wrappedCallable; - if (this.delegate != null) { - wrappedCallable = this.delegate.wrapCallable(c); - } - else { - wrappedCallable = c; - } - if (wrappedCallable instanceof SeataContextCallable) { - return wrappedCallable; - } - - return new SeataContextCallable<>(wrappedCallable, - RequestContextHolder.getRequestAttributes()); - } - - private static class SeataContextCallable implements Callable { - - private final Callable actual; - - private final String xid; - - private final RequestAttributes requestAttributes; - - SeataContextCallable(Callable actual, RequestAttributes requestAttribute) { - this.actual = actual; - this.requestAttributes = requestAttribute; - this.xid = RootContext.getXID(); - } - - @Override - public K call() throws Exception { - try { - RequestContextHolder.setRequestAttributes(requestAttributes); - if (!StringUtils.isEmpty(xid)) { - RootContext.bind(xid); - } - return actual.call(); - } - finally { - if (!StringUtils.isEmpty(xid)) { - RootContext.unbind(); - } - RequestContextHolder.resetRequestAttributes(); - } - } - - } - -} diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/resources/META-INF/spring.factories b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/resources/META-INF/spring.factories index 54b578ae..c4c1b218 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/resources/META-INF/spring.factories +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/resources/META-INF/spring.factories @@ -1,6 +1,5 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ com.alibaba.cloud.seata.rest.SeataRestTemplateAutoConfiguration,\ com.alibaba.cloud.seata.web.SeataHandlerInterceptorConfiguration,\ -com.alibaba.cloud.seata.feign.SeataFeignClientAutoConfiguration,\ -com.alibaba.cloud.seata.feign.hystrix.SeataHystrixAutoConfiguration +com.alibaba.cloud.seata.feign.SeataFeignClientAutoConfiguration diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sentinel/pom.xml b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sentinel/pom.xml index f97d4a91..3b52c94c 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sentinel/pom.xml +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sentinel/pom.xml @@ -75,6 +75,12 @@ true + + org.springframework.cloud + spring-cloud-starter-loadbalancer + true + + org.springframework.cloud spring-cloud-commons @@ -156,6 +162,12 @@ test + + junit + junit + test + + diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/feign/SentinelFeign.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/feign/SentinelFeign.java index 5b2f89d8..bb804474 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/feign/SentinelFeign.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/feign/SentinelFeign.java @@ -25,8 +25,8 @@ import feign.Contract; import feign.Feign; import feign.InvocationHandlerFactory; import feign.Target; -import feign.hystrix.FallbackFactory; -import feign.hystrix.HystrixFeign; +//import feign.hystrix.FallbackFactory; +//import feign.hystrix.HystrixFeign; import org.springframework.beans.BeansException; import org.springframework.cloud.openfeign.FeignContext; @@ -80,35 +80,35 @@ public final class SentinelFeign { // using reflect get fallback and fallbackFactory properties from // FeignClientFactoryBean because FeignClientFactoryBean is a package // level class, we can not use it in our package - Object feignClientFactoryBean = Builder.this.applicationContext - .getBean("&" + target.type().getName()); - - Class fallback = (Class) getFieldValue(feignClientFactoryBean, - "fallback"); - Class fallbackFactory = (Class) getFieldValue(feignClientFactoryBean, - "fallbackFactory"); - String beanName = (String) getFieldValue(feignClientFactoryBean, - "contextId"); - if (!StringUtils.hasText(beanName)) { - beanName = (String) getFieldValue(feignClientFactoryBean, "name"); - } - - Object fallbackInstance; - FallbackFactory fallbackFactoryInstance; - // check fallback and fallbackFactory properties - if (void.class != fallback) { - fallbackInstance = getFromContext(beanName, "fallback", fallback, - target.type()); - return new SentinelInvocationHandler(target, dispatch, - new FallbackFactory.Default(fallbackInstance)); - } - if (void.class != fallbackFactory) { - fallbackFactoryInstance = (FallbackFactory) getFromContext( - beanName, "fallbackFactory", fallbackFactory, - FallbackFactory.class); - return new SentinelInvocationHandler(target, dispatch, - fallbackFactoryInstance); - } +// Object feignClientFactoryBean = Builder.this.applicationContext +// .getBean("&" + target.type().getName()); +// +// Class fallback = (Class) getFieldValue(feignClientFactoryBean, +// "fallback"); +// Class fallbackFactory = (Class) getFieldValue(feignClientFactoryBean, +// "fallbackFactory"); +// String beanName = (String) getFieldValue(feignClientFactoryBean, +// "contextId"); +// if (!StringUtils.hasText(beanName)) { +// beanName = (String) getFieldValue(feignClientFactoryBean, "name"); +// } +// +// Object fallbackInstance; +// FallbackFactory fallbackFactoryInstance; +// // check fallback and fallbackFactory properties +// if (void.class != fallback) { +// fallbackInstance = getFromContext(beanName, "fallback", fallback, +// target.type()); +// return new SentinelInvocationHandler(target, dispatch, +// new FallbackFactory.Default(fallbackInstance)); +// } +// if (void.class != fallbackFactory) { +// fallbackFactoryInstance = (FallbackFactory) getFromContext( +// beanName, "fallbackFactory", fallbackFactory, +// FallbackFactory.class); +// return new SentinelInvocationHandler(target, dispatch, +// fallbackFactoryInstance); +// } return new SentinelInvocationHandler(target, dispatch); } diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/feign/SentinelInvocationHandler.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/feign/SentinelInvocationHandler.java index e5f80a62..85144c05 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/feign/SentinelInvocationHandler.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/feign/SentinelInvocationHandler.java @@ -33,7 +33,6 @@ import feign.Feign; import feign.InvocationHandlerFactory.MethodHandler; import feign.MethodMetadata; import feign.Target; -import feign.hystrix.FallbackFactory; import static feign.Util.checkNotNull; @@ -48,18 +47,8 @@ public class SentinelInvocationHandler implements InvocationHandler { private final Map dispatch; - private FallbackFactory fallbackFactory; - private Map fallbackMethodMap; - SentinelInvocationHandler(Target target, Map dispatch, - FallbackFactory fallbackFactory) { - this.target = checkNotNull(target, "target"); - this.dispatch = checkNotNull(dispatch, "dispatch"); - this.fallbackFactory = fallbackFactory; - this.fallbackMethodMap = toFallbackMethod(dispatch); - } - SentinelInvocationHandler(Target target, Map dispatch) { this.target = checkNotNull(target, "target"); this.dispatch = checkNotNull(dispatch, "dispatch"); @@ -111,25 +100,8 @@ public class SentinelInvocationHandler implements InvocationHandler { if (!BlockException.isBlockException(ex)) { Tracer.trace(ex); } - if (fallbackFactory != null) { - try { - Object fallbackResult = fallbackMethodMap.get(method) - .invoke(fallbackFactory.create(ex), args); - return fallbackResult; - } - catch (IllegalAccessException e) { - // shouldn't happen as method is public due to being an - // interface - throw new AssertionError(e); - } - catch (InvocationTargetException e) { - throw new AssertionError(e.getCause()); - } - } - else { - // throw exception if fallbackFactory is null - throw ex; - } + // throw exception if fallbackFactory is null + throw ex; } finally { if (entry != null) { diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sentinel/src/test/java/com/alibaba/cloud/sentinel/ContextIdSentinelFeignTests.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sentinel/src/test/java/com/alibaba/cloud/sentinel/ContextIdSentinelFeignTests.java index 7bd67724..79d0873a 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sentinel/src/test/java/com/alibaba/cloud/sentinel/ContextIdSentinelFeignTests.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sentinel/src/test/java/com/alibaba/cloud/sentinel/ContextIdSentinelFeignTests.java @@ -25,6 +25,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.cloud.openfeign.EnableFeignClients; +import org.springframework.cloud.openfeign.FallbackFactory; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -122,7 +123,7 @@ public class ContextIdSentinelFeignTests { } public static class CustomFallbackFactory - implements feign.hystrix.FallbackFactory { + implements FallbackFactory { private FooService fooService = new FooServiceFallback(); diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sentinel/src/test/java/com/alibaba/cloud/sentinel/SentinelFeignTests.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sentinel/src/test/java/com/alibaba/cloud/sentinel/SentinelFeignTests.java index 0939bf0b..b8efeece 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sentinel/src/test/java/com/alibaba/cloud/sentinel/SentinelFeignTests.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sentinel/src/test/java/com/alibaba/cloud/sentinel/SentinelFeignTests.java @@ -31,6 +31,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.cloud.openfeign.EnableFeignClients; +import org.springframework.cloud.openfeign.FallbackFactory; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -191,7 +192,7 @@ public class SentinelFeignTests { } public static class CustomFallbackFactory - implements feign.hystrix.FallbackFactory { + implements FallbackFactory { private FooService fooService = new FooServiceFallback(); diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/consul/SidecarConsulAutoRegistration.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/consul/SidecarConsulAutoRegistration.java index f53a0a1d..ecb51e17 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/consul/SidecarConsulAutoRegistration.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/consul/SidecarConsulAutoRegistration.java @@ -59,7 +59,7 @@ public class SidecarConsulAutoRegistration extends ConsulAutoRegistration { service.setAddress(sidecarProperties.getIp()); } service.setName(normalizeForDns(appName)); - service.setTags(createTags(properties)); + service.setTags(properties.getTags()); // set health check, use alibaba sidecar self's port rather than polyglot app's // port. diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/nacos/SidecarNacosDiscoveryProperties.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/nacos/SidecarNacosDiscoveryProperties.java index 1a7a6d87..c7513502 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/nacos/SidecarNacosDiscoveryProperties.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/nacos/SidecarNacosDiscoveryProperties.java @@ -37,7 +37,7 @@ public class SidecarNacosDiscoveryProperties extends NacosDiscoveryProperties { super.init(); String ip = sidecarProperties.getIp(); - if (!StringUtils.isEmpty(ip)) { + if (!StringUtils.hasText(ip)) { this.setIp(ip); } diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-bus-rocketmq/src/main/java/com/alibaba/cloud/bus/rocketmq/env/RocketMQBusEnvironmentPostProcessor.java b/spring-cloud-alibaba-starters/spring-cloud-starter-bus-rocketmq/src/main/java/com/alibaba/cloud/bus/rocketmq/env/RocketMQBusEnvironmentPostProcessor.java index d062dc23..f378bfa4 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-bus-rocketmq/src/main/java/com/alibaba/cloud/bus/rocketmq/env/RocketMQBusEnvironmentPostProcessor.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-bus-rocketmq/src/main/java/com/alibaba/cloud/bus/rocketmq/env/RocketMQBusEnvironmentPostProcessor.java @@ -28,7 +28,7 @@ import org.springframework.core.env.MapPropertySource; import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource; -import static org.springframework.cloud.bus.SpringCloudBusClient.INPUT; +import static org.springframework.cloud.bus.BusConstants.INPUT; /** * The lowest precedence {@link EnvironmentPostProcessor} configures default RocketMQ Bus diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-stream-rocketmq/pom.xml b/spring-cloud-alibaba-starters/spring-cloud-starter-stream-rocketmq/pom.xml index ec44c9d7..38be941f 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-stream-rocketmq/pom.xml +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-stream-rocketmq/pom.xml @@ -58,6 +58,13 @@ spring-boot-starter-test test + + + junit + junit + test + + diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-stream-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/integration/RocketMQMessageHandler.java b/spring-cloud-alibaba-starters/spring-cloud-starter-stream-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/integration/RocketMQMessageHandler.java index 2bf3fa62..6f89ff71 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-stream-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/integration/RocketMQMessageHandler.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-stream-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/integration/RocketMQMessageHandler.java @@ -131,7 +131,7 @@ public class RocketMQMessageHandler extends AbstractMessageHandler implements Li } } catch (MQClientException e) { - logger.error("fetch publish message queues fail", e); + logger.error(e, "fetch publish message queues fail"); } } running = true;