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-examples/sentinel-example/sentinel-zuul-example/pom.xml b/spring-cloud-alibaba-examples/sentinel-example/sentinel-zuul-example/pom.xml
deleted file mode 100644
index 6fff4420..00000000
--- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-zuul-example/pom.xml
+++ /dev/null
@@ -1,83 +0,0 @@
-
-
-
-
- com.alibaba.cloud
- spring-cloud-alibaba-examples
- ${revision}
- ../../pom.xml
-
- 4.0.0
-
-
- sentinel-zuul-example
- Spring Cloud Starter Alibaba Sentinel x Zuul Example
- Example demonstrating how to use sentinel with zuul
- jar
-
-
-
-
-
- com.alibaba.cloud
- spring-cloud-starter-alibaba-sentinel
-
-
-
- org.springframework.boot
- spring-boot-starter-web
-
-
-
- org.springframework.boot
- spring-boot-starter-actuator
-
-
-
- org.springframework.cloud
- spring-cloud-starter-netflix-zuul
-
-
-
- com.alibaba.cloud
- spring-cloud-alibaba-sentinel-gateway
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- org.springframework.boot
- spring-boot-maven-plugin
-
-
- org.apache.maven.plugins
- maven-deploy-plugin
- ${maven-deploy-plugin.version}
-
- true
-
-
-
-
-
-
diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-zuul-example/src/main/java/com/alibaba/cloud/examples/RulesController.java b/spring-cloud-alibaba-examples/sentinel-example/sentinel-zuul-example/src/main/java/com/alibaba/cloud/examples/RulesController.java
deleted file mode 100644
index 5475bcdd..00000000
--- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-zuul-example/src/main/java/com/alibaba/cloud/examples/RulesController.java
+++ /dev/null
@@ -1,53 +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;
-
-import java.util.List;
-import java.util.Set;
-
-import com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiDefinition;
-import com.alibaba.csp.sentinel.adapter.gateway.common.api.GatewayApiDefinitionManager;
-import com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayFlowRule;
-import com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayRuleManager;
-import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
-import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
-
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-/**
- * @author Jim
- */
-@RestController
-public class RulesController {
-
- @GetMapping("/api")
- public Set apiRules() {
- return GatewayApiDefinitionManager.getApiDefinitions();
- }
-
- @GetMapping("/gateway")
- public Set apiGateway() {
- return GatewayRuleManager.getRules();
- }
-
- @GetMapping("/flow")
- public List apiFlow() {
- return FlowRuleManager.getRules();
- }
-
-}
diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-zuul-example/src/main/java/com/alibaba/cloud/examples/SentinelZuulApplication.java b/spring-cloud-alibaba-examples/sentinel-example/sentinel-zuul-example/src/main/java/com/alibaba/cloud/examples/SentinelZuulApplication.java
deleted file mode 100644
index 476cbb05..00000000
--- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-zuul-example/src/main/java/com/alibaba/cloud/examples/SentinelZuulApplication.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;
-
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
-
-/**
- * @author Jim
- */
-@SpringBootApplication
-@EnableZuulProxy
-public class SentinelZuulApplication {
-
- public static void main(String[] args) {
- SpringApplication.run(SentinelZuulApplication.class, args);
- }
-
-}
diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-zuul-example/src/main/java/com/alibaba/cloud/examples/ZuulConfiguration.java b/spring-cloud-alibaba-examples/sentinel-example/sentinel-zuul-example/src/main/java/com/alibaba/cloud/examples/ZuulConfiguration.java
deleted file mode 100644
index 9dccb6b2..00000000
--- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-zuul-example/src/main/java/com/alibaba/cloud/examples/ZuulConfiguration.java
+++ /dev/null
@@ -1,68 +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;
-
-import javax.servlet.http.HttpServletRequest;
-
-import com.alibaba.csp.sentinel.adapter.gateway.zuul.callback.RequestOriginParser;
-import com.alibaba.csp.sentinel.adapter.gateway.zuul.fallback.BlockResponse;
-import com.alibaba.csp.sentinel.adapter.gateway.zuul.fallback.ZuulBlockFallbackProvider;
-
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-/**
- * @author Jim
- */
-@Configuration
-public class ZuulConfiguration {
-
- @Bean
- public ZuulBlockFallbackProvider zuulBlockFallbackProvider1() {
- return new ZuulBlockFallbackProvider() {
- @Override
- public String getRoute() {
- return "*";
- }
-
- @Override
- public BlockResponse fallbackResponse(String route, Throwable cause) {
- if ("my-service3".equals(route)) {
- return new BlockResponse(433, "Sentinel Block3", route);
- }
- else if ("my-service4".equals(route)) {
- return new BlockResponse(444, "my-service4", route);
- }
- else {
- return new BlockResponse(499, "Sentinel Block 499", route);
- }
- }
- };
- }
-
- @Bean
- public RequestOriginParser requestOriginParser() {
- return new RequestOriginParser() {
-
- @Override
- public String parseOrigin(HttpServletRequest request) {
- return "123";
- }
- };
- }
-
-}
diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-zuul-example/src/main/resources/api.json b/spring-cloud-alibaba-examples/sentinel-example/sentinel-zuul-example/src/main/resources/api.json
deleted file mode 100644
index 6de3c4fb..00000000
--- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-zuul-example/src/main/resources/api.json
+++ /dev/null
@@ -1,32 +0,0 @@
-[
- {
- "apiName": "some_customized_api",
- "predicateItems": [
- {
- "pattern": "/product/baz"
- },
- {
- "pattern": "/product/foo/**",
- "matchStrategy": 1
- },
- {
- "items": [
- {
- "pattern": "/spring-cloud/**"
- },
- {
- "pattern": "/spring-cloud-alibaba/**"
- }
- ]
- }
- ]
- },
- {
- "apiName": "another_customized_api",
- "predicateItems": [
- {
- "pattern": "/ahas"
- }
- ]
- }
-]
diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-zuul-example/src/main/resources/application.yaml b/spring-cloud-alibaba-examples/sentinel-example/sentinel-zuul-example/src/main/resources/application.yaml
deleted file mode 100644
index 0e9d9abf..00000000
--- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-zuul-example/src/main/resources/application.yaml
+++ /dev/null
@@ -1,40 +0,0 @@
-server:
- port: 18086
-spring:
- application:
- name: sentinel-zuul
- cloud:
- sentinel:
- datasource.ds2.file:
- file: "classpath: gateway.json"
- ruleType: gw-flow
- datasource.ds1.file:
- file: "classpath: api.json"
- ruleType: gw-api-group
- transport:
- dashboard: localhost:8080
- filter:
- enabled: false
-
-management.endpoints.web.exposure.include: "*"
-
-
-zuul.routes.my-service.path: "/product/foo/**"
-zuul.routes.my-service.service-id: "my-service"
-
-zuul.routes.my-service2.path: "/my-service2/**"
-zuul.routes.my-service2.service-id: "my-service2"
-
-zuul.routes.my-service3.path: "/my-service3/**"
-zuul.routes.my-service3.service-id: "my-service3"
-
-zuul.routes.my-service4.path: "/my-service4/**"
-zuul.routes.my-service4.service-id: "my-service4"
-
-
-spring.cloud.sentinel.zuul.order.pre: 2000
-spring.cloud.sentinel.zuul.order.post: 500
-spring.cloud.sentinel.zuul.order.error: -100
-
-
-spring.cloud.sentinel.zuul.enabled: true
\ No newline at end of file
diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-zuul-example/src/main/resources/gateway.json b/spring-cloud-alibaba-examples/sentinel-example/sentinel-zuul-example/src/main/resources/gateway.json
deleted file mode 100644
index b3effe88..00000000
--- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-zuul-example/src/main/resources/gateway.json
+++ /dev/null
@@ -1,26 +0,0 @@
-[
- {
- "resource": "some_customized_api",
- "count": 0
- },
- {
- "resource": "my-service2",
- "count": 0
- },
- {
- "resource": "my-service3",
- "count": 0,
- "paramItem": {
- "parseStrategy": 2,
- "fieldName": "Spring-Cloud-Alibaba"
- }
- },
- {
- "resource": "my-service4",
- "count": 0,
- "paramItem": {
- "parseStrategy": 3,
- "fieldName": "name"
- }
- }
-]
diff --git a/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-consumer-sample/pom.xml b/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-consumer-sample/pom.xml
index 3b855121..0746af1e 100644
--- a/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-consumer-sample/pom.xml
+++ b/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-consumer-sample/pom.xml
@@ -99,7 +99,11 @@
org.springframework.cloud
spring-cloud-starter-consul-discovery
- ${spring-cloud-consul.version}
+
+
+
+ org.springframework.cloud
+ spring-cloud-starter-bootstrap
diff --git a/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-provider-sample/pom.xml b/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-provider-sample/pom.xml
index d7e932e7..71ed7e28 100644
--- a/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-provider-sample/pom.xml
+++ b/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-provider-sample/pom.xml
@@ -90,7 +90,6 @@
org.springframework.cloud
spring-cloud-starter-consul-discovery
- ${spring-cloud-consul.version}
@@ -134,6 +133,11 @@
hibernate-validator
+
+ org.springframework.cloud
+ spring-cloud-starter-bootstrap
+
+
diff --git a/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-provider-web-sample/pom.xml b/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-provider-web-sample/pom.xml
index d434ebb1..95999e0f 100644
--- a/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-provider-web-sample/pom.xml
+++ b/spring-cloud-alibaba-examples/spring-cloud-alibaba-dubbo-examples/spring-cloud-dubbo-provider-web-sample/pom.xml
@@ -89,7 +89,6 @@
org.springframework.cloud
spring-cloud-starter-consul-discovery
- ${spring-cloud-consul.version}
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/pom.xml b/spring-cloud-alibaba-starters/spring-cloud-alibaba-sentinel-gateway/pom.xml
index 49283a18..04fe730f 100644
--- a/spring-cloud-alibaba-starters/spring-cloud-alibaba-sentinel-gateway/pom.xml
+++ b/spring-cloud-alibaba-starters/spring-cloud-alibaba-sentinel-gateway/pom.xml
@@ -23,12 +23,6 @@
true
-
- org.springframework.cloud
- spring-cloud-starter-netflix-zuul
- true
-
-
com.alibaba.csp
sentinel-api-gateway-adapter-common
@@ -39,11 +33,6 @@
sentinel-parameter-flow-control
-
- com.alibaba.csp
- sentinel-zuul-adapter
-
-
com.alibaba.csp
sentinel-spring-cloud-gateway-adapter
diff --git a/spring-cloud-alibaba-starters/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/ConfigConstants.java b/spring-cloud-alibaba-starters/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/ConfigConstants.java
index 8158fdef..b86a887d 100644
--- a/spring-cloud-alibaba-starters/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/ConfigConstants.java
+++ b/spring-cloud-alibaba-starters/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/ConfigConstants.java
@@ -17,28 +17,17 @@
package com.alibaba.cloud.sentinel.gateway;
import com.alibaba.cloud.sentinel.gateway.scg.SentinelGatewayProperties;
-import com.alibaba.cloud.sentinel.gateway.zuul.SentinelZuulProperties;
/**
* @author Jim
*/
public final class ConfigConstants {
- /**
- * Netflix Zuul type.
- */
- public static final String APP_TYPE_ZUUL_GATEWAY = "12";
-
/**
* Spring Cloud Gateway type.
*/
public static final String APP_TYPE_SCG_GATEWAY = "11";
- /**
- * ConfigurationProperties for {@link SentinelZuulProperties}.
- */
- public static final String ZUUL_PREFIX = "spring.cloud.sentinel.zuul";
-
/**
* ConfigurationProperties for {@link SentinelGatewayProperties}.
*/
diff --git a/spring-cloud-alibaba-starters/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/zuul/FallBackProviderHandler.java b/spring-cloud-alibaba-starters/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/zuul/FallBackProviderHandler.java
deleted file mode 100644
index dd08bd24..00000000
--- a/spring-cloud-alibaba-starters/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/zuul/FallBackProviderHandler.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.sentinel.gateway.zuul;
-
-import java.util.Map;
-
-import com.alibaba.csp.sentinel.adapter.gateway.zuul.fallback.DefaultBlockFallbackProvider;
-import com.alibaba.csp.sentinel.adapter.gateway.zuul.fallback.ZuulBlockFallbackManager;
-import com.alibaba.csp.sentinel.adapter.gateway.zuul.fallback.ZuulBlockFallbackProvider;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.springframework.beans.factory.SmartInitializingSingleton;
-import org.springframework.beans.factory.support.DefaultListableBeanFactory;
-import org.springframework.util.CollectionUtils;
-
-/**
- * @author tiger
- */
-public class FallBackProviderHandler implements SmartInitializingSingleton {
-
- private static final Logger logger = LoggerFactory
- .getLogger(FallBackProviderHandler.class);
-
- private final DefaultListableBeanFactory beanFactory;
-
- public FallBackProviderHandler(DefaultListableBeanFactory beanFactory) {
- this.beanFactory = beanFactory;
- }
-
- @Override
- public void afterSingletonsInstantiated() {
- Map providerMap = beanFactory
- .getBeansOfType(ZuulBlockFallbackProvider.class);
- if (!CollectionUtils.isEmpty(providerMap)) {
- providerMap.forEach((k, v) -> {
- logger.info("[Sentinel Zuul] Register provider name:{}, instance: {}", k,
- v);
- ZuulBlockFallbackManager.registerProvider(v);
- });
- }
- else {
- logger.info("[Sentinel Zuul] Register default fallback provider. ");
- ZuulBlockFallbackManager.registerProvider(new DefaultBlockFallbackProvider());
- }
- }
-
-}
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
deleted file mode 100644
index 3f6cbd6c..00000000
--- a/spring-cloud-alibaba-starters/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/zuul/SentinelZuulAutoConfiguration.java
+++ /dev/null
@@ -1,102 +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.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/java/com/alibaba/cloud/sentinel/gateway/zuul/SentinelZuulProperties.java b/spring-cloud-alibaba-starters/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/zuul/SentinelZuulProperties.java
deleted file mode 100644
index f1ab8da7..00000000
--- a/spring-cloud-alibaba-starters/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/zuul/SentinelZuulProperties.java
+++ /dev/null
@@ -1,89 +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.sentinel.gateway.zuul;
-
-import com.alibaba.cloud.sentinel.gateway.ConfigConstants;
-import com.alibaba.csp.sentinel.adapter.gateway.zuul.constants.ZuulConstant;
-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 org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.boot.context.properties.NestedConfigurationProperty;
-
-/**
- * @author Jim
- */
-@ConfigurationProperties(prefix = ConfigConstants.ZUUL_PREFIX)
-public class SentinelZuulProperties {
-
- @NestedConfigurationProperty
- private SentinelZuulProperties.Order order = new SentinelZuulProperties.Order();
-
- public Order getOrder() {
- return order;
- }
-
- public SentinelZuulProperties setOrder(Order order) {
- this.order = order;
- return this;
- }
-
- public static class Order {
-
- /**
- * The order of {@link SentinelZuulPreFilter}.
- */
- private int pre = 10000;
-
- /**
- * The order of {@link SentinelZuulPostFilter}.
- */
- private int post = ZuulConstant.SEND_RESPONSE_FILTER_ORDER;
-
- /**
- * The order of {@link SentinelZuulErrorFilter}.
- */
- private int error = -1;
-
- public int getPre() {
- return pre;
- }
-
- public void setPre(int pre) {
- this.pre = pre;
- }
-
- public int getPost() {
- return post;
- }
-
- public void setPost(int post) {
- this.post = post;
- }
-
- public int getError() {
- return error;
- }
-
- public void setError(int error) {
- this.error = error;
- }
-
- }
-
-}
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-config-server/pom.xml b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-config-server/pom.xml
index 483914cf..a17aae08 100644
--- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-config-server/pom.xml
+++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-config-server/pom.xml
@@ -51,12 +51,6 @@
test
-
- org.springframework.cloud
- spring-cloud-test-support
- test
-
-
org.springframework.boot
spring-boot-starter
diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-config/pom.xml b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-config/pom.xml
index 0a36d2c8..f6a2e185 100644
--- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-config/pom.xml
+++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-config/pom.xml
@@ -33,6 +33,12 @@
true
+
+ org.springframework.cloud
+ spring-cloud-starter-bootstrap
+ true
+
+
org.springframework.boot
spring-boot
@@ -85,12 +91,6 @@
test
-
- org.springframework.cloud
- spring-cloud-test-support
- test
-
-
org.powermock
diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/pom.xml b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/pom.xml
index 02a3c3e3..ab023806 100644
--- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/pom.xml
+++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/pom.xml
@@ -81,11 +81,6 @@
spring-cloud-context
-
- org.springframework.cloud
- spring-cloud-starter-netflix-ribbon
-
-
org.springframework.cloud
spring-cloud-config-client
@@ -111,12 +106,6 @@
test
-
- org.springframework.cloud
- spring-cloud-test-support
- test
-
-
io.projectreactor
reactor-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/pom.xml b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/pom.xml
index 3f3e1a2e..315856bd 100644
--- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/pom.xml
+++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/pom.xml
@@ -92,12 +92,6 @@
true
-
- org.springframework.cloud
- spring-cloud-starter-netflix-ribbon
- true
-
-
org.springframework.boot
spring-boot-starter-test
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..701ef10c 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,14 +38,6 @@ 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.alibaba.csp.sentinel.SphU")
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..5e0369a1 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,10 @@ 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.openfeign.loadbalancer.FeignBlockingLoadBalancerClient;
-import org.springframework.cloud.openfeign.ribbon.CachingSpringLoadBalancerFactory;
-import org.springframework.cloud.openfeign.ribbon.LoadBalancerFeignClient;
/**
* @author xiaojing
@@ -37,9 +36,6 @@ public class SeataFeignObjectWrapper {
private final BeanFactory beanFactory;
- private CachingSpringLoadBalancerFactory cachingSpringLoadBalancerFactory;
-
- private SpringClientFactory springClientFactory;
SeataFeignObjectWrapper(BeanFactory beanFactory) {
this.beanFactory = beanFactory;
@@ -47,35 +43,16 @@ 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 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;
- }
-
- 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
deleted file mode 100644
index 98fb605f..00000000
--- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataHystrixFeignBuilder.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.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
deleted file mode 100644
index 8204fed8..00000000
--- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataLoadBalancerFeignClient.java
+++ /dev/null
@@ -1,48 +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;
-
-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);
- }
-
-}
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 40dc3596..28604c27 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
@@ -83,7 +83,7 @@
org.springframework.cloud
- spring-cloud-starter-netflix-ribbon
+ spring-cloud-starter-loadbalancer
true
@@ -162,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..2624aae6 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,18 +25,20 @@ import feign.Contract;
import feign.Feign;
import feign.InvocationHandlerFactory;
import feign.Target;
-import feign.hystrix.FallbackFactory;
-import feign.hystrix.HystrixFeign;
import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.cloud.openfeign.FallbackFactory;
+import org.springframework.cloud.openfeign.FeignClientFactoryBean;
import org.springframework.cloud.openfeign.FeignContext;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
+import org.springframework.context.support.GenericApplicationContext;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.StringUtils;
/**
- * {@link Feign.Builder} like {@link HystrixFeign.Builder}.
+ * {@link Feign.Builder}.
*
* @author Jim
*/
@@ -77,20 +79,22 @@ public final class SentinelFeign {
@Override
public InvocationHandler create(Target target,
Map dispatch) {
- // 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");
+ GenericApplicationContext gctx = (GenericApplicationContext) Builder.this.applicationContext;
+ BeanDefinition def = gctx.getBeanDefinition(target.type().getName());
+
+ /**
+ * Due to the change of the initialization sequence, BeanFactory.getBean will cause a circular dependency.
+ * So FeignClientFactoryBean can only be obtained from BeanDefinition
+ */
+ FeignClientFactoryBean feignClientFactoryBean = (FeignClientFactoryBean) def.getAttribute("feignClientsRegistrarFactoryBean");
+
+ Class fallback = feignClientFactoryBean.getFallback();
+ Class fallbackFactory = feignClientFactoryBean.getFallbackFactory();
+ String beanName = feignClientFactoryBean.getContextId();
+
if (!StringUtils.hasText(beanName)) {
- beanName = (String) getFieldValue(feignClientFactoryBean, "name");
+ beanName = feignClientFactoryBean.getName();
}
Object fallbackInstance;
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..92436d9e 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,8 @@ import feign.Feign;
import feign.InvocationHandlerFactory.MethodHandler;
import feign.MethodMetadata;
import feign.Target;
-import feign.hystrix.FallbackFactory;
+
+import org.springframework.cloud.openfeign.FallbackFactory;
import static feign.Util.checkNotNull;
@@ -71,7 +72,8 @@ public class SentinelInvocationHandler implements InvocationHandler {
if ("equals".equals(method.getName())) {
try {
Object otherHandler = args.length > 0 && args[0] != null
- ? Proxy.getInvocationHandler(args[0]) : null;
+ ? Proxy.getInvocationHandler(args[0])
+ : null;
return equals(otherHandler);
}
catch (IllegalArgumentException e) {
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..051faea3 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
@@ -16,7 +16,10 @@
package com.alibaba.cloud.sidecar.consul;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
import com.alibaba.cloud.sidecar.SidecarProperties;
import com.ecwid.consul.v1.agent.model.NewService;
@@ -29,6 +32,8 @@ import org.springframework.cloud.consul.serviceregistry.ConsulManagementRegistra
import org.springframework.cloud.consul.serviceregistry.ConsulRegistrationCustomizer;
import org.springframework.context.ApplicationContext;
import org.springframework.core.env.Environment;
+import org.springframework.util.CollectionUtils;
+import org.springframework.util.StringUtils;
/**
* @author www.itmuch.com
@@ -59,16 +64,28 @@ public class SidecarConsulAutoRegistration extends ConsulAutoRegistration {
service.setAddress(sidecarProperties.getIp());
}
service.setName(normalizeForDns(appName));
- service.setTags(createTags(properties));
+ service.setTags(new ArrayList<>(properties.getTags()));
+ service.setEnableTagOverride(properties.getEnableTagOverride());
+ service.setMeta(getMetadata(properties));
- // set health check, use alibaba sidecar self's port rather than polyglot app's
- // port.
- service.setPort(
- Integer.valueOf(context.getEnvironment().getProperty("server.port")));
- setCheck(service, autoServiceRegistrationProperties, properties, context,
- heartbeatProperties);
+ if (sidecarProperties.getPort() != null && sidecarProperties.getPort() > 0) {
+ service.setPort(properties.getPort());
+ }
+ else if (properties.getPort() != null && properties.getPort() > 0) {
+ service.setPort(properties.getPort());
+ }
+ else if (context.getEnvironment().getProperty("server.port") != null) {
+ // set health check, use alibaba sidecar self's port rather than polyglot
+ // app's port.
+ service.setPort(
+ Integer.valueOf(context.getEnvironment().getProperty("server.port")));
+ }
- service.setPort(sidecarProperties.getPort());
+ if (service.getPort() != null) {
+ // we know the port and can set the check
+ setCheck(service, autoServiceRegistrationProperties, properties, context,
+ heartbeatProperties);
+ }
ConsulAutoRegistration registration = new ConsulAutoRegistration(service,
autoServiceRegistrationProperties, properties, context,
@@ -77,6 +94,33 @@ public class SidecarConsulAutoRegistration extends ConsulAutoRegistration {
return registration;
}
+ /**
+ * copyed from
+ * org.springframework.cloud.consul.serviceregistry.ConsulAutoRegistration#getMetadata.
+ */
+ private static Map getMetadata(ConsulDiscoveryProperties properties) {
+ LinkedHashMap metadata = new LinkedHashMap<>();
+ if (!CollectionUtils.isEmpty(properties.getMetadata())) {
+ metadata.putAll(properties.getMetadata());
+ }
+
+ // add metadata from other properties. See createTags above.
+ if (!StringUtils.isEmpty(properties.getInstanceZone())) {
+ metadata.put(properties.getDefaultZoneMetadataName(),
+ properties.getInstanceZone());
+ }
+ if (!StringUtils.isEmpty(properties.getInstanceGroup())) {
+ metadata.put("group", properties.getInstanceGroup());
+ }
+
+ // store the secure flag in the tags so that clients will be able to figure
+ // out whether to use http or https automatically
+ metadata.put("secure",
+ Boolean.toString(properties.getScheme().equalsIgnoreCase("https")));
+
+ return metadata;
+ }
+
public static String getInstanceId(SidecarProperties sidecarProperties,
Environment environment) {
return String.format("%s-%s-%s",
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-dubbo/pom.xml b/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/pom.xml
index 34b013b7..b404252b 100644
--- a/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/pom.xml
+++ b/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/pom.xml
@@ -78,7 +78,6 @@
org.springframework.cloud
spring-cloud-starter-zookeeper-discovery
- ${spring-cloud-zookeeper.version}
true
@@ -112,7 +111,6 @@
org.springframework.cloud
spring-cloud-starter-consul-discovery
- ${spring-cloud-consul.version}
true
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;