From 0db3b26fd6edf735a5a2aaedfb9e42c0a2d963c8 Mon Sep 17 00:00:00 2001 From: theonefx Date: Fri, 3 Apr 2020 10:38:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=BA=E4=BA=8EF=E7=89=88=E7=9A=84=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=E9=80=82=E9=85=8D=E6=80=A7=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 131 ++++++++- spring-cloud-alibaba-coverage/pom.xml | 6 - spring-cloud-alibaba-dependencies/pom.xml | 157 ++-------- spring-cloud-alibaba-docs/pom.xml | 2 + .../pom.xml | 79 ----- .../scripts/error.sh | 7 - .../scripts/feign-defaultmethod-error.sh | 7 - .../scripts/feign-error.sh | 7 - .../scripts/index.sh | 7 - .../scripts/resttemplate.sh | 7 - .../scripts/sleep.sh | 7 - .../examples/ConsumerSCLBApplication.java | 243 ---------------- .../examples/MyLoadBalancerConfiguration.java | 44 --- .../alibaba/cloud/examples/UrlCleaner.java | 30 -- .../src/main/resources/application.properties | 22 -- .../src/main/resources/degraderule.json | 26 -- .../src/main/resources/flowrule.json | 10 - .../pom.xml | 63 ---- .../examples/ConsumerReactiveApplication.java | 74 ----- .../src/main/resources/application.properties | 9 - .../nacos-discovery-example/pom.xml | 2 - .../cloud/examples/ServiceApplication.java | 19 -- .../cloud/examples/TestController.java | 17 -- .../cloud/examples/MyConfiguration.java | 26 -- .../examples/SentinelWebFluxController.java | 28 -- .../pom.xml | 40 +-- spring-cloud-alibaba-starters/pom.xml | 1 - .../META-INF/sentinel-datasource.properties | 2 +- .../pom.xml | 67 ----- .../ReactiveSentinelCircuitBreaker.java | 104 ------- ...ntinelCircuitBreakerAutoConfiguration.java | 67 ----- ...ReactiveSentinelCircuitBreakerFactory.java | 59 ---- .../sentinel/SentinelCircuitBreaker.java | 114 -------- ...ntinelCircuitBreakerAutoConfiguration.java | 68 ----- .../SentinelCircuitBreakerFactory.java | 57 ---- .../sentinel/SentinelConfigBuilder.java | 112 -------- ...itional-spring-configuration-metadata.json | 7 - .../main/resources/META-INF/spring.factories | 3 - ...SentinelCircuitBreakerIntegrationTest.java | 209 -------------- .../ReactiveSentinelCircuitBreakerTest.java | 80 ------ ...SentinelCircuitBreakerIntegrationTest.java | 155 ---------- .../sentinel/SentinelCircuitBreakerTest.java | 85 ------ .../pom.xml | 14 + .../NacosDiscoveryClientConfiguration.java | 5 +- ...ntConfigServiceBootstrapConfiguration.java | 4 +- .../NacosReactiveDiscoveryClient.java | 84 ------ ...sReactiveDiscoveryClientConfiguration.java | 52 ---- .../main/resources/META-INF/spring.factories | 1 - ...tiveDiscoveryClientConfigurationTests.java | 45 --- .../NacosReactiveDiscoveryClientTests.java | 74 ----- .../pom.xml | 6 - .../SeataFeignBlockingLoadBalancerClient.java | 45 --- .../seata/feign/SeataFeignObjectWrapper.java | 7 - .../pom.xml | 5 - .../endpoint/SentinelHealthIndicator.java | 11 +- .../feign/SentinelContractHolder.java | 4 +- .../cloud/sentinel/feign/SentinelFeign.java | 7 +- .../feign/SentinelInvocationHandler.java | 2 +- .../sentinel/ContextIdSentinelFeignTests.java | 272 +++++++++--------- .../SidecarConsulAutoConfiguration.java | 4 +- .../consul/SidecarConsulAutoRegistration.java | 9 +- .../DubboServiceBeanMetadataResolver.java | 4 +- ...ubboTransportedMethodMetadataResolver.java | 2 +- .../RocketMQMessageChannelBinder.java | 40 +-- .../integration/RocketMQMessageHandler.java | 9 +- .../integration/RocketMQMessageSource.java | 9 +- .../properties/RocketMQBindingProperties.java | 6 +- .../RocketMQExtendedBindingProperties.java | 67 ++++- .../RocketMQAutoConfigurationTests.java | 4 +- 69 files changed, 412 insertions(+), 2640 deletions(-) delete mode 100644 spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/pom.xml delete mode 100644 spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/scripts/error.sh delete mode 100644 spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/scripts/feign-defaultmethod-error.sh delete mode 100644 spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/scripts/feign-error.sh delete mode 100644 spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/scripts/index.sh delete mode 100644 spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/scripts/resttemplate.sh delete mode 100644 spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/scripts/sleep.sh delete mode 100644 spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/src/main/java/com/alibaba/cloud/examples/ConsumerSCLBApplication.java delete mode 100644 spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/src/main/java/com/alibaba/cloud/examples/MyLoadBalancerConfiguration.java delete mode 100644 spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/src/main/java/com/alibaba/cloud/examples/UrlCleaner.java delete mode 100644 spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/src/main/resources/application.properties delete mode 100644 spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/src/main/resources/degraderule.json delete mode 100644 spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/src/main/resources/flowrule.json delete mode 100644 spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-reactivediscovery-consumer-example/pom.xml delete mode 100644 spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-reactivediscovery-consumer-example/src/main/java/com/alibaba/cloud/examples/ConsumerReactiveApplication.java delete mode 100644 spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-reactivediscovery-consumer-example/src/main/resources/application.properties delete mode 100644 spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/pom.xml delete mode 100644 spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/ReactiveSentinelCircuitBreaker.java delete mode 100644 spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/ReactiveSentinelCircuitBreakerAutoConfiguration.java delete mode 100644 spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/ReactiveSentinelCircuitBreakerFactory.java delete mode 100644 spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/SentinelCircuitBreaker.java delete mode 100644 spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/SentinelCircuitBreakerAutoConfiguration.java delete mode 100644 spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/SentinelCircuitBreakerFactory.java delete mode 100644 spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/SentinelConfigBuilder.java delete mode 100644 spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/main/resources/META-INF/additional-spring-configuration-metadata.json delete mode 100644 spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/main/resources/META-INF/spring.factories delete mode 100644 spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/test/java/com/alibaba/cloud/circuitbreaker/sentinel/ReactiveSentinelCircuitBreakerIntegrationTest.java delete mode 100644 spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/test/java/com/alibaba/cloud/circuitbreaker/sentinel/ReactiveSentinelCircuitBreakerTest.java delete mode 100644 spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/test/java/com/alibaba/cloud/circuitbreaker/sentinel/SentinelCircuitBreakerIntegrationTest.java delete mode 100644 spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/test/java/com/alibaba/cloud/circuitbreaker/sentinel/SentinelCircuitBreakerTest.java delete mode 100644 spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/discovery/reactive/NacosReactiveDiscoveryClient.java delete mode 100644 spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/discovery/reactive/NacosReactiveDiscoveryClientConfiguration.java delete mode 100644 spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/discovery/reactive/NacosReactiveDiscoveryClientConfigurationTests.java delete mode 100644 spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/discovery/reactive/NacosReactiveDiscoveryClientTests.java delete mode 100644 spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignBlockingLoadBalancerClient.java diff --git a/pom.xml b/pom.xml index 93be9ecf..bd1d368a 100644 --- a/pom.xml +++ b/pom.xml @@ -45,8 +45,10 @@ flystar32@163.com - fangjian + Jim Fang fangjian0423@gmail.com + Alibaba + https://github.com/fangjian0423 xiaolongzuo @@ -76,7 +78,9 @@ 2.0.4.RELEASE 2.0.2.RELEASE 2.0.4.RELEASE + Elmhurst.SR3 2.0.3.RELEASE + 2.0.5.RELEASE 2.0.2.RELEASE 4.12 @@ -84,7 +88,7 @@ 1.7.25 - 2.7.3 + 2.7.4.1 4.0.1 @@ -96,6 +100,13 @@ 2.21.0 1.6 0.8.3 + 0.0.9 + + + 8.18 + 0.0.7 + 3.0.0 + 0.0.2.RELEASE @@ -109,7 +120,7 @@ - + org.springframework.boot spring-boot-dependencies @@ -143,7 +154,7 @@ org.springframework.cloud - spring-cloud-netflix + spring-cloud-netflix-dependencies ${spring-cloud-netflix.version} pom import @@ -157,6 +168,14 @@ import + + org.springframework.cloud + spring-cloud-config-dependencies + ${spring-cloud-config.version} + pom + import + + org.springframework.cloud spring-cloud-bus-dependencies @@ -173,6 +192,14 @@ import + + org.springframework.cloud + spring-cloud-stream-dependencies + ${spring-cloud-stream.version} + pom + import + + org.springframework.cloud spring-cloud-consul-dependencies @@ -189,6 +216,21 @@ import + + + org.apache.dubbo + dubbo-dependencies-bom + ${dubbo.version} + pom + import + + + org.springframework + spring-framework-bom + + + + org.apache.dubbo dubbo-spring-boot-starter @@ -208,15 +250,7 @@ org.springframework - spring - - - javax.servlet - servlet-api - - - log4j - log4j + spring-context @@ -230,6 +264,15 @@ + + + + org.jacoco + jacoco-maven-plugin + ${jacoco.version} + + + org.apache.maven.plugins @@ -252,6 +295,56 @@ + + io.spring.javaformat + spring-javaformat-maven-plugin + ${spring-javaformat.version} + + + org.apache.maven.plugins + maven-checkstyle-plugin + ${maven-checkstyle-plugin.version} + + + com.puppycrawl.tools + checkstyle + ${puppycrawl-tools-checkstyle.version} + + + io.spring.javaformat + spring-javaformat-checkstyle + ${spring-javaformat-checkstyle.version} + + + org.springframework.cloud + spring-cloud-build-tools + ${spring-cloud-build.version} + + + io.spring.nohttp + nohttp-checkstyle + ${nohttp-checkstyle.version} + + + + + checkstyle-validation + validate + + check + + + + eclipse/checkstyle-suppressions.xml + true + true + true + true + warning + + + + org.apache.maven.plugins maven-compiler-plugin @@ -276,7 +369,17 @@ + + + + org.apache.maven.plugins + maven-checkstyle-plugin + + + + + spring @@ -338,6 +441,8 @@ + + \ No newline at end of file diff --git a/spring-cloud-alibaba-coverage/pom.xml b/spring-cloud-alibaba-coverage/pom.xml index 1b460f9a..22a70502 100644 --- a/spring-cloud-alibaba-coverage/pom.xml +++ b/spring-cloud-alibaba-coverage/pom.xml @@ -28,12 +28,6 @@ ${project.version} - - com.alibaba.cloud - spring-cloud-circuitbreaker-sentinel - ${project.version} - - com.alibaba.cloud spring-cloud-starter-alibaba-seata diff --git a/spring-cloud-alibaba-dependencies/pom.xml b/spring-cloud-alibaba-dependencies/pom.xml index 8210127c..75bbfaeb 100644 --- a/spring-cloud-alibaba-dependencies/pom.xml +++ b/spring-cloud-alibaba-dependencies/pom.xml @@ -18,8 +18,8 @@ Spring Cloud Alibaba Dependencies - 1.7.0 - 0.9.0 + 1.7.1 + 1.1.0 1.2.1 0.8.0 4.4.1 @@ -34,42 +34,6 @@ - - - com.alibaba.cloud - alicloud-context - ${alicloud.context.version} - - - com.aliyun - aliyun-java-sdk-edas - ${aliyun.sdk.edas.version} - - - com.aliyun - aliyun-java-sdk-core - - - - - com.aliyun - aliyun-java-sdk-core - ${aliyun.sdk.version} - - - - - com.aliyun.mns - aliyun-sdk-mns - ${aliyun.sdk.mns} - - - - com.aliyun - aliyun-java-sdk-dysmsapi - ${aliyun.java.sdk.dysmsapi} - - com.alibaba.nacos @@ -89,6 +53,7 @@ sentinel-core ${sentinel.version} + com.alibaba.csp sentinel-parameter-flow-control @@ -99,31 +64,37 @@ sentinel-datasource-extension ${sentinel.version} + com.alibaba.csp sentinel-datasource-apollo ${sentinel.version} + com.alibaba.csp sentinel-datasource-zookeeper ${sentinel.version} + com.alibaba.csp sentinel-datasource-nacos ${sentinel.version} + com.alibaba.csp sentinel-datasource-redis ${sentinel.version} + com.alibaba.csp sentinel-web-servlet ${sentinel.version} + com.alibaba.csp sentinel-zuul-adapter @@ -134,21 +105,25 @@ sentinel-spring-cloud-gateway-adapter ${sentinel.version} + com.alibaba.csp sentinel-transport-simple-http ${sentinel.version} + com.alibaba.csp sentinel-annotation-aspectj ${sentinel.version} + com.alibaba.csp sentinel-dubbo-adapter ${sentinel.version} + com.alibaba.csp sentinel-apache-dubbo-adapter @@ -166,11 +141,13 @@ sentinel-cluster-server-default ${sentinel.version} + com.alibaba.csp sentinel-cluster-client-default ${sentinel.version} + com.alibaba.csp sentinel-spring-webflux-adapter @@ -196,11 +173,6 @@ - - com.alibaba.cloud - spring-cloud-alibaba-sentinel - ${project.version} - com.alibaba.cloud spring-cloud-alibaba-sentinel-datasource @@ -211,71 +183,6 @@ spring-cloud-alibaba-sentinel-gateway ${project.version} - - com.alibaba.cloud - spring-cloud-alicloud-oss - ${project.version} - - - com.alibaba.cloud - spring-cloud-alibaba-nacos-discovery - ${project.version} - - - com.alibaba.cloud - spring-cloud-alibaba-nacos-config - ${project.version} - - - com.alibaba.cloud - spring-cloud-alibaba-nacos-config-server - ${project.version} - - - com.alibaba.cloud - spring-cloud-alibaba-seata - ${project.version} - - - com.alibaba.cloud - spring-cloud-alicloud-acm - ${project.version} - - - com.alibaba.cloud - spring-cloud-alicloud-ans - ${project.version} - - - com.alibaba.cloud - spring-cloud-alicloud-schedulerx - ${project.version} - - - com.alibaba.cloud - spring-cloud-alicloud-sms - ${project.version} - - - com.alibaba.cloud - spring-cloud-alicloud-context - ${project.version} - - - com.alibaba.cloud - spring-cloud-stream-binder-rocketmq - ${project.version} - - - com.alibaba.cloud - spring-cloud-alibaba-dubbo - ${project.version} - - - com.alibaba.cloud - spring-cloud-alibaba-sidecar - ${project.version} - @@ -284,12 +191,6 @@ ${project.version} - - com.alibaba.cloud - spring-cloud-circuitbreaker-sentinel - ${project.version} - - com.alibaba.cloud spring-cloud-starter-alibaba-seata @@ -313,24 +214,6 @@ ${project.version} - - com.alibaba.cloud - spring-cloud-starter-alicloud-ans - ${project.version} - - - - com.alibaba.cloud - spring-cloud-starter-alicloud-acm - ${project.version} - - - - com.alibaba.cloud - spring-cloud-starter-alicloud-schedulerx - ${project.version} - - com.alibaba.cloud spring-cloud-starter-stream-rocketmq @@ -368,6 +251,7 @@ + spring @@ -419,7 +303,16 @@ false + + spring-releases + Spring Releases + https://repo.spring.io/libs-release-local + + false + + + diff --git a/spring-cloud-alibaba-docs/pom.xml b/spring-cloud-alibaba-docs/pom.xml index a3ac653f..64a9296d 100644 --- a/spring-cloud-alibaba-docs/pom.xml +++ b/spring-cloud-alibaba-docs/pom.xml @@ -6,7 +6,9 @@ com.alibaba.cloud spring-cloud-alibaba 2.0.1.RELEASE + ../pom.xml + 4.0.0 spring-cloud-alibaba-docs diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/pom.xml b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/pom.xml deleted file mode 100644 index f38168ad..00000000 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/pom.xml +++ /dev/null @@ -1,79 +0,0 @@ - - - - - com.alibaba.cloud - nacos-discovery-example - 2.0.1.RELEASE - - 4.0.0 - - - nacos-discovery-consumer-sclb-example - jar - Example demonstrating how to use nacos discovery - - - - - org.springframework.boot - spring-boot-starter-web - - - com.alibaba.cloud - spring-cloud-starter-alibaba-nacos-discovery - - - org.springframework.cloud - spring-cloud-starter-netflix-ribbon - - - - - - org.springframework.boot - spring-boot-starter-actuator - - - - - - - - - com.alibaba.cloud - spring-cloud-starter-alibaba-sentinel - - - - org.springframework.cloud - spring-cloud-starter-openfeign - - - org.springframework.cloud - spring-cloud-starter-netflix-ribbon - - - - - - - - - - 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/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/scripts/error.sh b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/scripts/error.sh deleted file mode 100644 index 5602a98d..00000000 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/scripts/error.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash -n=1 -while [ $n -le 10 ] -do - echo `curl -s http://localhost:18083/test` - let n++ -done diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/scripts/feign-defaultmethod-error.sh b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/scripts/feign-defaultmethod-error.sh deleted file mode 100644 index 6efb8368..00000000 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/scripts/feign-defaultmethod-error.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash -n=1 -while [ $n -le 10 ] -do - echo `curl -s http://localhost:18083/divide-feign2?a=1` - let n++ -done diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/scripts/feign-error.sh b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/scripts/feign-error.sh deleted file mode 100644 index 09db2477..00000000 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/scripts/feign-error.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash -n=1 -while [ $n -le 10 ] -do - echo `curl -s http://localhost:18083/divide-feign?a=1\&b=0` - let n++ -done diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/scripts/index.sh b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/scripts/index.sh deleted file mode 100644 index 7db176b8..00000000 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/scripts/index.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash -n=1 -while [ $n -le 10 ] -do - echo `curl -s http://localhost:18083/index` - let n++ -done diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/scripts/resttemplate.sh b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/scripts/resttemplate.sh deleted file mode 100644 index e9d2e630..00000000 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/scripts/resttemplate.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash -n=1 -while [ $n -le 10 ] -do - echo `curl -s http://localhost:18083/echo-rest/resttemplate` - let n++ -done diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/scripts/sleep.sh b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/scripts/sleep.sh deleted file mode 100644 index 423c3d15..00000000 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/scripts/sleep.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash -n=1 -while [ $n -le 10 ] -do - echo `curl -s http://localhost:18083/sleep` - let n++ -done diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/src/main/java/com/alibaba/cloud/examples/ConsumerSCLBApplication.java b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/src/main/java/com/alibaba/cloud/examples/ConsumerSCLBApplication.java deleted file mode 100644 index 9cb57f9b..00000000 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/src/main/java/com/alibaba/cloud/examples/ConsumerSCLBApplication.java +++ /dev/null @@ -1,243 +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.Random; - -import com.alibaba.cloud.examples.ConsumerSCLBApplication.EchoService; -import com.alibaba.cloud.sentinel.annotation.SentinelRestTemplate; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import reactor.core.publisher.Mono; - -import org.springframework.beans.factory.ObjectProvider; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.cloud.client.ServiceInstance; -import org.springframework.cloud.client.discovery.DiscoveryClient; -import org.springframework.cloud.client.discovery.EnableDiscoveryClient; -import org.springframework.cloud.client.loadbalancer.LoadBalanced; -import org.springframework.cloud.client.loadbalancer.reactive.DefaultResponse; -import org.springframework.cloud.client.loadbalancer.reactive.EmptyResponse; -import org.springframework.cloud.client.loadbalancer.reactive.Request; -import org.springframework.cloud.client.loadbalancer.reactive.Response; -import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClient; -import org.springframework.cloud.loadbalancer.core.NoopServiceInstanceListSupplier; -import org.springframework.cloud.loadbalancer.core.ReactorServiceInstanceLoadBalancer; -import org.springframework.cloud.loadbalancer.core.ServiceInstanceListSupplier; -import org.springframework.cloud.openfeign.EnableFeignClients; -import org.springframework.cloud.openfeign.FeignClient; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.client.RestTemplate; - -/** - * @author Jim - */ -@SpringBootApplication -@EnableDiscoveryClient(autoRegister = false) -@EnableFeignClients -public class ConsumerSCLBApplication { - - @LoadBalanced - @Bean - @SentinelRestTemplate(urlCleanerClass = UrlCleaner.class, urlCleaner = "clean") - public RestTemplate restTemplate() { - return new RestTemplate(); - } - - @LoadBalanced - @Bean - @SentinelRestTemplate - public RestTemplate restTemplate1() { - return new RestTemplate(); - } - - public static void main(String[] args) { - SpringApplication.run(ConsumerSCLBApplication.class, args); - } - - @Configuration - @LoadBalancerClient(value = "service-provider", - configuration = MyLoadBalancerConfiguration.class) - class MySCLBConfiguration { - - } - - static class RandomLoadBalancer implements ReactorServiceInstanceLoadBalancer { - - private static final Logger log = LoggerFactory - .getLogger(RandomLoadBalancer.class); - - private ObjectProvider serviceInstanceListSupplierProvider; - - private final String serviceId; - - private final Random random; - - RandomLoadBalancer( - ObjectProvider serviceInstanceListSupplierProvider, - String serviceId) { - this.serviceInstanceListSupplierProvider = serviceInstanceListSupplierProvider; - this.serviceId = serviceId; - this.random = new Random(); - } - - @Override - public Mono> choose(Request request) { - log.info("random spring cloud loadbalacer active -.-"); - ServiceInstanceListSupplier supplier = serviceInstanceListSupplierProvider - .getIfAvailable(NoopServiceInstanceListSupplier::new); - return supplier.get().next().map(this::getInstanceResponse); - } - - private Response getInstanceResponse( - List instances) { - if (instances.isEmpty()) { - return new EmptyResponse(); - } - ServiceInstance instance = instances.get(random.nextInt(instances.size())); - - return new DefaultResponse(instance); - } - - } - - @FeignClient(name = "service-provider", fallback = EchoServiceFallback.class, - configuration = FeignConfiguration.class) - public interface EchoService { - - @GetMapping("/echo/{str}") - String echo(@PathVariable("str") String str); - - @GetMapping("/divide") - String divide(@RequestParam("a") Integer a, @RequestParam("b") Integer b); - - default String divide(Integer a) { - return divide(a, 0); - } - - @GetMapping("/notFound") - String notFound(); - - } - - @RestController - class TestController { - - @Autowired - private RestTemplate restTemplate; - - @Autowired - private RestTemplate restTemplate1; - - @Autowired - private EchoService echoService; - - @Autowired - private DiscoveryClient discoveryClient; - - @GetMapping("/echo-rest/{str}") - public String rest(@PathVariable String str) { - return restTemplate.getForObject("http://service-provider/echo/" + str, - String.class); - } - - @GetMapping("/echo-feign/{str}") - public String feign(@PathVariable String str) { - return echoService.echo(str); - } - - @GetMapping("/index") - public String index() { - return restTemplate1.getForObject("http://service-provider", String.class); - } - - @GetMapping("/test") - public String test() { - return restTemplate1.getForObject("http://service-provider/test", - String.class); - } - - @GetMapping("/sleep") - public String sleep() { - return restTemplate1.getForObject("http://service-provider/sleep", - String.class); - } - - @GetMapping("/notFound-feign") - public String notFound() { - return echoService.notFound(); - } - - @GetMapping("/divide-feign") - public String divide(@RequestParam Integer a, @RequestParam Integer b) { - return echoService.divide(a, b); - } - - @GetMapping("/divide-feign2") - public String divide(@RequestParam Integer a) { - return echoService.divide(a); - } - - @GetMapping("/services/{service}") - public Object client(@PathVariable String service) { - return discoveryClient.getInstances(service); - } - - @GetMapping("/services") - public Object services() { - return discoveryClient.getServices(); - } - - } - -} - -class FeignConfiguration { - - @Bean - public EchoServiceFallback echoServiceFallback() { - return new EchoServiceFallback(); - } - -} - -class EchoServiceFallback implements EchoService { - - @Override - public String echo(@PathVariable("str") String str) { - return "echo fallback"; - } - - @Override - public String divide(@RequestParam Integer a, @RequestParam Integer b) { - return "divide fallback"; - } - - @Override - public String notFound() { - return "notFound fallback"; - } - -} diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/src/main/java/com/alibaba/cloud/examples/MyLoadBalancerConfiguration.java b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/src/main/java/com/alibaba/cloud/examples/MyLoadBalancerConfiguration.java deleted file mode 100644 index 8ff96657..00000000 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/src/main/java/com/alibaba/cloud/examples/MyLoadBalancerConfiguration.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; - -import com.alibaba.cloud.examples.ConsumerSCLBApplication.RandomLoadBalancer; - -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.cloud.client.ServiceInstance; -import org.springframework.cloud.loadbalancer.core.ReactorLoadBalancer; -import org.springframework.cloud.loadbalancer.core.ServiceInstanceListSupplier; -import org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory; -import org.springframework.context.annotation.Bean; -import org.springframework.core.env.Environment; - -/** - * @author Jim - */ -public class MyLoadBalancerConfiguration { - - @Bean - @ConditionalOnMissingBean - public ReactorLoadBalancer reactorServiceInstanceLoadBalancer( - Environment environment, - LoadBalancerClientFactory loadBalancerClientFactory) { - String name = environment.getProperty(LoadBalancerClientFactory.PROPERTY_NAME); - return new RandomLoadBalancer(loadBalancerClientFactory.getLazyProvider(name, - ServiceInstanceListSupplier.class), name); - } - -} diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/src/main/java/com/alibaba/cloud/examples/UrlCleaner.java b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/src/main/java/com/alibaba/cloud/examples/UrlCleaner.java deleted file mode 100644 index e0c691af..00000000 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/src/main/java/com/alibaba/cloud/examples/UrlCleaner.java +++ /dev/null @@ -1,30 +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; - -public class UrlCleaner { - - public static String clean(String url) { - System.out.println("enter urlCleaner"); - if (url.matches(".*/echo/.*")) { - System.out.println("change url"); - url = url.replaceAll("/echo/.*", "/echo/{str}"); - } - return url; - } - -} diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/src/main/resources/application.properties b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/src/main/resources/application.properties deleted file mode 100644 index 656e35c5..00000000 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/src/main/resources/application.properties +++ /dev/null @@ -1,22 +0,0 @@ -spring.application.name=service-consumer-sclb -server.port=18083 -management.endpoints.web.exposure.include=* -spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848 - -spring.cloud.nacos.username=nacos -spring.cloud.nacos.password=nacos - -spring.cloud.loadbalancer.ribbon.enabled=false - -feign.sentinel.enabled=true - -spring.cloud.sentinel.transport.dashboard=localhost:8080 -spring.cloud.sentinel.eager=true - -spring.cloud.sentinel.datasource.ds1.file.file=classpath: flowrule.json -spring.cloud.sentinel.datasource.ds1.file.data-type=json -spring.cloud.sentinel.datasource.ds1.file.rule-type=flow - -spring.cloud.sentinel.datasource.ds2.file.file=classpath: degraderule.json -spring.cloud.sentinel.datasource.ds2.file.data-type=json -spring.cloud.sentinel.datasource.ds2.file.rule-type=degrade diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/src/main/resources/degraderule.json b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/src/main/resources/degraderule.json deleted file mode 100644 index 75e9d3b3..00000000 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/src/main/resources/degraderule.json +++ /dev/null @@ -1,26 +0,0 @@ -[ - { - "resource": "GET:http://service-provider/test", - "count": 0.5, - "grade": 1, - "timeWindow": 30 - }, - { - "resource": "GET:http://service-provider", - "count": 0.5, - "grade": 1, - "timeWindow": 10 - }, - { - "resource": "GET:http://service-provider/sleep", - "count": 20.0, - "grade": 0, - "timeWindow": 30 - }, - { - "resource": "GET:http://service-provider/divide", - "count": 0.5, - "grade": 1, - "timeWindow": 30 - } -] \ No newline at end of file diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/src/main/resources/flowrule.json b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/src/main/resources/flowrule.json deleted file mode 100644 index 5260bbe6..00000000 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-sclb-example/src/main/resources/flowrule.json +++ /dev/null @@ -1,10 +0,0 @@ -[ - { - "resource": "GET:http://service-provider/echo/{str}", - "controlBehavior": 0, - "count": 2, - "grade": 1, - "limitApp": "default", - "strategy": 0 - } -] diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-reactivediscovery-consumer-example/pom.xml b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-reactivediscovery-consumer-example/pom.xml deleted file mode 100644 index 9d7e8207..00000000 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-reactivediscovery-consumer-example/pom.xml +++ /dev/null @@ -1,63 +0,0 @@ - - - - - com.alibaba.cloud - nacos-discovery-example - 2.0.1.RELEASE - - 4.0.0 - - - nacos-reactivediscovery-consumer-example - jar - Example demonstrating how to use nacos discovery - - - - - org.springframework.boot - spring-boot-starter-webflux - - - com.alibaba.cloud - spring-cloud-starter-alibaba-nacos-discovery - - - org.springframework.cloud - spring-cloud-starter-netflix-ribbon - - - - - - org.springframework.boot - spring-boot-starter-actuator - - - - - - - - - - - - - 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/nacos-example/nacos-discovery-example/nacos-reactivediscovery-consumer-example/src/main/java/com/alibaba/cloud/examples/ConsumerReactiveApplication.java b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-reactivediscovery-consumer-example/src/main/java/com/alibaba/cloud/examples/ConsumerReactiveApplication.java deleted file mode 100644 index b9e05737..00000000 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-reactivediscovery-consumer-example/src/main/java/com/alibaba/cloud/examples/ConsumerReactiveApplication.java +++ /dev/null @@ -1,74 +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 reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.cloud.client.discovery.ReactiveDiscoveryClient; -import org.springframework.cloud.client.loadbalancer.LoadBalanced; -import org.springframework.context.annotation.Bean; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.reactive.function.client.WebClient; - -/** - * @author Jim - */ -@SpringBootApplication -public class ConsumerReactiveApplication { - - @Bean - @LoadBalanced - public WebClient.Builder webClient() { - return WebClient.builder(); - } - - public static void main(String[] args) { - SpringApplication.run(ConsumerReactiveApplication.class, args); - } - - @RestController - class MyController { - - @Autowired - private ReactiveDiscoveryClient reactiveDiscoveryClient; - - @Autowired - private WebClient.Builder webClientBuilder; - - @GetMapping("/all-services") - public Flux allServices() { - return reactiveDiscoveryClient.getInstances("service-provider") - .map(serviceInstance -> serviceInstance.getHost() + ":" - + serviceInstance.getPort()); - } - - @GetMapping("/service-call/{name}") - public Mono serviceCall(@PathVariable("name") String name) { - return webClientBuilder.build().get() - .uri("http://service-provider/echo/" + name).retrieve() - .bodyToMono(String.class); - } - - } - -} diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-reactivediscovery-consumer-example/src/main/resources/application.properties b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-reactivediscovery-consumer-example/src/main/resources/application.properties deleted file mode 100644 index 4cdd63be..00000000 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-reactivediscovery-consumer-example/src/main/resources/application.properties +++ /dev/null @@ -1,9 +0,0 @@ -spring.application.name=service-consumer-reactive -server.port=18083 -management.endpoints.web.exposure.include=* -spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848 - -spring.cloud.nacos.username=nacos -spring.cloud.nacos.password=nacos - -spring.cloud.loadbalancer.ribbon.enabled=false diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/pom.xml b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/pom.xml index 929f6a2b..792d611f 100644 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/pom.xml +++ b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/pom.xml @@ -18,8 +18,6 @@ nacos-discovery-consumer-example - nacos-discovery-consumer-sclb-example - nacos-reactivediscovery-consumer-example nacos-discovery-provider-example nacos-discovery-spring-cloud-config-server-example nacos-discovery-spring-cloud-config-client-example diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/java/com/alibaba/cloud/examples/ServiceApplication.java b/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/java/com/alibaba/cloud/examples/ServiceApplication.java index 7345f74c..17121bd9 100644 --- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/java/com/alibaba/cloud/examples/ServiceApplication.java +++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/java/com/alibaba/cloud/examples/ServiceApplication.java @@ -16,18 +16,11 @@ package com.alibaba.cloud.examples; -import java.util.Collections; - -import com.alibaba.cloud.circuitbreaker.sentinel.SentinelCircuitBreakerFactory; -import com.alibaba.cloud.circuitbreaker.sentinel.SentinelConfigBuilder; import com.alibaba.cloud.sentinel.annotation.SentinelRestTemplate; import com.alibaba.csp.sentinel.datasource.Converter; -import com.alibaba.csp.sentinel.slots.block.RuleConstant; -import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.cloud.client.circuitbreaker.Customizer; import org.springframework.context.annotation.Bean; import org.springframework.web.client.RestTemplate; @@ -54,18 +47,6 @@ public class ServiceApplication { return new JsonFlowRuleListConverter(); } - @Bean - public Customizer defaultConfig() { - return factory -> { - factory.configureDefault( - id -> new SentinelConfigBuilder().resourceName(id) - .rules(Collections.singletonList(new DegradeRule(id) - .setGrade(RuleConstant.DEGRADE_GRADE_RT).setCount(100) - .setTimeWindow(10))) - .build()); - }; - } - public static void main(String[] args) { SpringApplication.run(ServiceApplication.class, args); } diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/java/com/alibaba/cloud/examples/TestController.java b/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/java/com/alibaba/cloud/examples/TestController.java index 5ca27cd1..1e7a909d 100644 --- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/java/com/alibaba/cloud/examples/TestController.java +++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/java/com/alibaba/cloud/examples/TestController.java @@ -19,7 +19,6 @@ package com.alibaba.cloud.examples; import com.alibaba.csp.sentinel.annotation.SentinelResource; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.cloud.client.circuitbreaker.CircuitBreakerFactory; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate; @@ -33,9 +32,6 @@ public class TestController { @Autowired private RestTemplate restTemplate; - @Autowired - private CircuitBreakerFactory circuitBreakerFactory; - @GetMapping("/hello") @SentinelResource("resource") public String hello() { @@ -58,17 +54,4 @@ public class TestController { return restTemplate.getForObject("http://www.taobao.com/test", String.class); } - @GetMapping("/slow") - public String slow() { - return circuitBreakerFactory.create("slow").run(() -> { - try { - Thread.sleep(500L); - } - catch (InterruptedException e) { - e.printStackTrace(); - } - return "slow"; - }, throwable -> "fallback"); - } - } diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-webflux-example/src/main/java/com/alibaba/cloud/examples/MyConfiguration.java b/spring-cloud-alibaba-examples/sentinel-example/sentinel-webflux-example/src/main/java/com/alibaba/cloud/examples/MyConfiguration.java index c1912ab4..c02f8c87 100644 --- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-webflux-example/src/main/java/com/alibaba/cloud/examples/MyConfiguration.java +++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-webflux-example/src/main/java/com/alibaba/cloud/examples/MyConfiguration.java @@ -16,16 +16,9 @@ package com.alibaba.cloud.examples; -import java.util.Collections; - -import com.alibaba.cloud.circuitbreaker.sentinel.ReactiveSentinelCircuitBreakerFactory; -import com.alibaba.cloud.circuitbreaker.sentinel.SentinelConfigBuilder; import com.alibaba.csp.sentinel.adapter.spring.webflux.callback.BlockRequestHandler; -import com.alibaba.csp.sentinel.slots.block.RuleConstant; -import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule; import reactor.core.publisher.Mono; -import org.springframework.cloud.client.circuitbreaker.Customizer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpStatus; @@ -53,23 +46,4 @@ public class MyConfiguration { }; } - @Bean - public Customizer slowCustomizer() { - return factory -> { - factory.configure(builder -> builder.rules(Collections.singletonList( - new DegradeRule("slow_mono").setGrade(RuleConstant.DEGRADE_GRADE_RT) - .setCount(100).setTimeWindow(5))), - "slow_mono"); - factory.configure(builder -> builder.rules(Collections.singletonList( - new DegradeRule("slow_flux").setGrade(RuleConstant.DEGRADE_GRADE_RT) - .setCount(100).setTimeWindow(5))), - "slow_flux"); - factory.configureDefault(id -> new SentinelConfigBuilder().resourceName(id) - .rules(Collections.singletonList(new DegradeRule(id) - .setGrade(RuleConstant.DEGRADE_GRADE_EXCEPTION_COUNT) - .setCount(0.5).setTimeWindow(10))) - .build()); - }; - } - } diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-webflux-example/src/main/java/com/alibaba/cloud/examples/SentinelWebFluxController.java b/spring-cloud-alibaba-examples/sentinel-example/sentinel-webflux-example/src/main/java/com/alibaba/cloud/examples/SentinelWebFluxController.java index d0b45891..5bf96332 100644 --- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-webflux-example/src/main/java/com/alibaba/cloud/examples/SentinelWebFluxController.java +++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-webflux-example/src/main/java/com/alibaba/cloud/examples/SentinelWebFluxController.java @@ -20,11 +20,8 @@ import com.alibaba.csp.sentinel.adapter.reactor.SentinelReactorTransformer; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.cloud.client.circuitbreaker.ReactiveCircuitBreakerFactory; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.reactive.function.client.WebClient; /** * @author Jim @@ -32,9 +29,6 @@ import org.springframework.web.reactive.function.client.WebClient; @RestController public class SentinelWebFluxController { - @Autowired - private ReactiveCircuitBreakerFactory circuitBreakerFactory; - @GetMapping("/mono") public Mono mono() { return Mono.just("simple string") @@ -56,26 +50,4 @@ public class SentinelWebFluxController { .transform(new SentinelReactorTransformer<>("flux")); } - @GetMapping("/cbSlow") - public Mono cbSlow() { - int delaySecs = 2; - return WebClient.builder().baseUrl("http://httpbin.org/").build().get() - .uri("/delay/" + delaySecs).retrieve().bodyToMono(String.class) - .transform(it -> circuitBreakerFactory.create("slow_mono").run(it, t -> { - t.printStackTrace(); - return Mono.just("fallback"); - })); - } - - @GetMapping("/cbError") - public Mono cbError() { - String code = "500"; - return WebClient.builder().baseUrl("http://httpbin.org/").build().get() - .uri("/status/" + code).retrieve().bodyToMono(String.class) - .transform(it -> circuitBreakerFactory.create("cbError").run(it, t -> { - t.printStackTrace(); - return Mono.just("fallback"); - })); - } - } 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 987800e5..ca91e747 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 @@ -104,30 +104,30 @@ validation-api - - - - + + org.jboss.resteasy + resteasy-jaxrs + - - - - + + org.jboss.resteasy + resteasy-client + - - - - + + org.jboss.resteasy + resteasy-netty4 + - - - - + + org.jboss.resteasy + resteasy-jackson-provider + - - - - + + org.jboss.resteasy + resteasy-jaxb-provider + org.hibernate.validator diff --git a/spring-cloud-alibaba-starters/pom.xml b/spring-cloud-alibaba-starters/pom.xml index 85d7f028..37d437d4 100644 --- a/spring-cloud-alibaba-starters/pom.xml +++ b/spring-cloud-alibaba-starters/pom.xml @@ -23,7 +23,6 @@ spring-cloud-starter-bus-rocketmq spring-cloud-starter-dubbo spring-cloud-starter-alibaba-sidecar - spring-cloud-circuitbreaker-sentinel spring-cloud-starter-alibaba-sentinel spring-cloud-alibaba-sentinel-datasource spring-cloud-alibaba-sentinel-gateway diff --git a/spring-cloud-alibaba-starters/spring-cloud-alibaba-sentinel-datasource/src/main/resources/META-INF/sentinel-datasource.properties b/spring-cloud-alibaba-starters/spring-cloud-alibaba-sentinel-datasource/src/main/resources/META-INF/sentinel-datasource.properties index 3fa290ee..074751fb 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-alibaba-sentinel-datasource/src/main/resources/META-INF/sentinel-datasource.properties +++ b/spring-cloud-alibaba-starters/spring-cloud-alibaba-sentinel-datasource/src/main/resources/META-INF/sentinel-datasource.properties @@ -2,4 +2,4 @@ nacos = com.alibaba.csp.sentinel.datasource.nacos.NacosDataSource file =com.alibaba.csp.sentinel.datasource.FileRefreshableDataSource apollo = com.alibaba.csp.sentinel.datasource.apollo.ApolloDataSource zk = com.alibaba.csp.sentinel.datasource.zookeeper.ZookeeperDataSource -redis = com.alibaba.csp.sentinel.datasource.redis.RedisDataSource \ No newline at end of file +redis = com.alibaba.csp.sentinel.datasource.redis.RedisDataSource diff --git a/spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/pom.xml b/spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/pom.xml deleted file mode 100644 index 3f389f8e..00000000 --- a/spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/pom.xml +++ /dev/null @@ -1,67 +0,0 @@ - - - - - com.alibaba.cloud - spring-cloud-alibaba-starters - 2.0.1.RELEASE - ../pom.xml - - - 4.0.0 - - spring-cloud-circuitbreaker-sentinel - Spring Cloud Circuit Breaker Sentinel - - - - - org.springframework.cloud - spring-cloud-commons - - - - com.alibaba.csp - sentinel-core - - - - com.alibaba.csp - sentinel-reactor-adapter - - - - org.springframework.boot - spring-boot-starter-web - true - - - - io.projectreactor - reactor-core - true - - - - - org.springframework.boot - spring-boot-starter-webflux - test - - - - org.springframework.boot - spring-boot-starter-test - test - - - - io.projectreactor - reactor-test - test - - - - - diff --git a/spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/ReactiveSentinelCircuitBreaker.java b/spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/ReactiveSentinelCircuitBreaker.java deleted file mode 100644 index 37e5a2f6..00000000 --- a/spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/ReactiveSentinelCircuitBreaker.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright 2013-2019 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.circuitbreaker.sentinel; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.function.Function; - -import com.alibaba.csp.sentinel.EntryType; -import com.alibaba.csp.sentinel.adapter.reactor.EntryConfig; -import com.alibaba.csp.sentinel.adapter.reactor.SentinelReactorTransformer; -import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule; -import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRuleManager; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; - -import org.springframework.cloud.client.circuitbreaker.ReactiveCircuitBreaker; -import org.springframework.util.Assert; - -/** - * Sentinel implementation of {@link ReactiveCircuitBreaker}. - * - * @author Eric Zhao - */ -public class ReactiveSentinelCircuitBreaker implements ReactiveCircuitBreaker { - - private final String resourceName; - - private final EntryType entryType; - - private final List rules; - - public ReactiveSentinelCircuitBreaker(String resourceName, EntryType entryType, - List rules) { - Assert.hasText(resourceName, "resourceName cannot be blank"); - Assert.notNull(rules, "rules should not be null"); - this.resourceName = resourceName; - this.entryType = entryType; - this.rules = Collections.unmodifiableList(rules); - - applyToSentinelRuleManager(); - } - - public ReactiveSentinelCircuitBreaker(String resourceName, List rules) { - this(resourceName, EntryType.OUT, rules); - } - - public ReactiveSentinelCircuitBreaker(String resourceName) { - this(resourceName, EntryType.OUT, Collections.emptyList()); - } - - private void applyToSentinelRuleManager() { - if (this.rules == null || this.rules.isEmpty()) { - return; - } - Set ruleSet = new HashSet<>(DegradeRuleManager.getRules()); - for (DegradeRule rule : this.rules) { - if (rule == null) { - continue; - } - rule.setResource(resourceName); - ruleSet.add(rule); - } - DegradeRuleManager.loadRules(new ArrayList<>(ruleSet)); - } - - @Override - public Mono run(Mono toRun, Function> fallback) { - Mono toReturn = toRun.transform(new SentinelReactorTransformer<>( - new EntryConfig(resourceName, entryType))); - if (fallback != null) { - toReturn = toReturn.onErrorResume(fallback); - } - return toReturn; - } - - @Override - public Flux run(Flux toRun, Function> fallback) { - Flux toReturn = toRun.transform(new SentinelReactorTransformer<>( - new EntryConfig(resourceName, entryType))); - if (fallback != null) { - toReturn = toReturn.onErrorResume(fallback); - } - return toReturn; - } - -} diff --git a/spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/ReactiveSentinelCircuitBreakerAutoConfiguration.java b/spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/ReactiveSentinelCircuitBreakerAutoConfiguration.java deleted file mode 100644 index 974ad2cf..00000000 --- a/spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/ReactiveSentinelCircuitBreakerAutoConfiguration.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2013-2019 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.circuitbreaker.sentinel; - -import java.util.ArrayList; -import java.util.List; - -import javax.annotation.PostConstruct; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.cloud.client.circuitbreaker.Customizer; -import org.springframework.cloud.client.circuitbreaker.ReactiveCircuitBreakerFactory; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * @author Eric Zhao - */ -@Configuration -@ConditionalOnClass( - name = { "reactor.core.publisher.Mono", "reactor.core.publisher.Flux" }) -@ConditionalOnProperty(name = "spring.cloud.circuitbreaker.sentinel.enabled", - havingValue = "true", matchIfMissing = true) -public class ReactiveSentinelCircuitBreakerAutoConfiguration { - - @Bean - @ConditionalOnMissingBean(ReactiveCircuitBreakerFactory.class) - public ReactiveCircuitBreakerFactory reactiveSentinelCircuitBreakerFactory() { - return new ReactiveSentinelCircuitBreakerFactory(); - } - - @Configuration - @ConditionalOnClass( - name = { "reactor.core.publisher.Mono", "reactor.core.publisher.Flux" }) - public static class ReactiveSentinelCustomizerConfiguration { - - @Autowired(required = false) - private List> customizers = new ArrayList<>(); - - @Autowired(required = false) - private ReactiveSentinelCircuitBreakerFactory factory; - - @PostConstruct - public void init() { - customizers.forEach(customizer -> customizer.customize(factory)); - } - - } - -} diff --git a/spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/ReactiveSentinelCircuitBreakerFactory.java b/spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/ReactiveSentinelCircuitBreakerFactory.java deleted file mode 100644 index a56d9b8e..00000000 --- a/spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/ReactiveSentinelCircuitBreakerFactory.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2013-2019 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.circuitbreaker.sentinel; - -import java.util.ArrayList; -import java.util.function.Function; - -import com.alibaba.cloud.circuitbreaker.sentinel.SentinelConfigBuilder.SentinelCircuitBreakerConfiguration; - -import org.springframework.cloud.client.circuitbreaker.ReactiveCircuitBreaker; -import org.springframework.cloud.client.circuitbreaker.ReactiveCircuitBreakerFactory; -import org.springframework.util.Assert; - -/** - * Factory for {@link ReactiveSentinelCircuitBreaker}. - * - * @author Eric Zhao - */ -public class ReactiveSentinelCircuitBreakerFactory extends - ReactiveCircuitBreakerFactory { - - private Function defaultConfiguration = id -> new SentinelConfigBuilder() - .resourceName(id).rules(new ArrayList<>()).build(); - - @Override - public ReactiveCircuitBreaker create(String id) { - Assert.hasText(id, "A CircuitBreaker must have an id."); - SentinelConfigBuilder.SentinelCircuitBreakerConfiguration conf = getConfigurations() - .computeIfAbsent(id, defaultConfiguration); - return new ReactiveSentinelCircuitBreaker(id, conf.getEntryType(), - conf.getRules()); - } - - @Override - protected SentinelConfigBuilder configBuilder(String id) { - return new SentinelConfigBuilder(id); - } - - @Override - public void configureDefault( - Function defaultConfiguration) { - this.defaultConfiguration = defaultConfiguration; - } - -} diff --git a/spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/SentinelCircuitBreaker.java b/spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/SentinelCircuitBreaker.java deleted file mode 100644 index 34ef0344..00000000 --- a/spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/SentinelCircuitBreaker.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright 2013-2019 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.circuitbreaker.sentinel; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.function.Function; -import java.util.function.Supplier; - -import com.alibaba.csp.sentinel.Entry; -import com.alibaba.csp.sentinel.EntryType; -import com.alibaba.csp.sentinel.SphU; -import com.alibaba.csp.sentinel.Tracer; -import com.alibaba.csp.sentinel.slots.block.BlockException; -import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule; -import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRuleManager; - -import org.springframework.cloud.client.circuitbreaker.CircuitBreaker; -import org.springframework.util.Assert; - -/** - * Sentinel implementation of {@link CircuitBreaker}. - * - * @author Eric Zhao - */ -public class SentinelCircuitBreaker implements CircuitBreaker { - - private final String resourceName; - - private final EntryType entryType; - - private final List rules; - - public SentinelCircuitBreaker(String resourceName, EntryType entryType, - List rules) { - Assert.hasText(resourceName, "resourceName cannot be blank"); - Assert.notNull(rules, "rules should not be null"); - this.resourceName = resourceName; - this.entryType = entryType; - this.rules = Collections.unmodifiableList(rules); - - applyToSentinelRuleManager(); - } - - public SentinelCircuitBreaker(String resourceName, List rules) { - this(resourceName, EntryType.OUT, rules); - } - - public SentinelCircuitBreaker(String resourceName) { - this(resourceName, EntryType.OUT, Collections.emptyList()); - } - - private void applyToSentinelRuleManager() { - if (this.rules == null || this.rules.isEmpty()) { - return; - } - Set ruleSet = new HashSet<>(DegradeRuleManager.getRules()); - for (DegradeRule rule : this.rules) { - if (rule == null) { - continue; - } - rule.setResource(resourceName); - ruleSet.add(rule); - } - DegradeRuleManager.loadRules(new ArrayList<>(ruleSet)); - } - - @Override - public T run(Supplier toRun, Function fallback) { - Entry entry = null; - try { - entry = SphU.entry(resourceName, entryType); - // If the SphU.entry() does not throw `BlockException`, it means that the - // request can pass. - return toRun.get(); - } - catch (BlockException ex) { - // SphU.entry() may throw BlockException which indicates that - // the request was rejected (flow control or circuit breaking triggered). - // So it should not be counted as the business exception. - return fallback.apply(ex); - } - catch (Exception ex) { - // For other kinds of exceptions, we'll trace the exception count via - // Tracer.trace(ex). - Tracer.trace(ex); - return fallback.apply(ex); - } - finally { - // Guarantee the invocation has been completed. - if (entry != null) { - entry.exit(); - } - } - } - -} diff --git a/spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/SentinelCircuitBreakerAutoConfiguration.java b/spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/SentinelCircuitBreakerAutoConfiguration.java deleted file mode 100644 index d4b37325..00000000 --- a/spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/SentinelCircuitBreakerAutoConfiguration.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2013-2019 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.circuitbreaker.sentinel; - -import java.util.ArrayList; -import java.util.List; - -import javax.annotation.PostConstruct; - -import com.alibaba.csp.sentinel.SphU; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.cloud.client.circuitbreaker.CircuitBreakerFactory; -import org.springframework.cloud.client.circuitbreaker.Customizer; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * Auto configuration for {@link SentinelCircuitBreaker}. - * - * @author Eric Zhao - */ -@Configuration -@ConditionalOnClass({ SphU.class }) -@ConditionalOnProperty(name = "spring.cloud.circuitbreaker.sentinel.enabled", - havingValue = "true", matchIfMissing = true) -public class SentinelCircuitBreakerAutoConfiguration { - - @Bean - @ConditionalOnMissingBean(CircuitBreakerFactory.class) - public CircuitBreakerFactory sentinelCircuitBreakerFactory() { - return new SentinelCircuitBreakerFactory(); - } - - @Configuration - public static class SentinelCustomizerConfiguration { - - @Autowired(required = false) - private List> customizers = new ArrayList<>(); - - @Autowired(required = false) - private SentinelCircuitBreakerFactory factory; - - @PostConstruct - public void init() { - customizers.forEach(customizer -> customizer.customize(factory)); - } - - } - -} diff --git a/spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/SentinelCircuitBreakerFactory.java b/spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/SentinelCircuitBreakerFactory.java deleted file mode 100644 index 692555e4..00000000 --- a/spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/SentinelCircuitBreakerFactory.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2013-2019 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.circuitbreaker.sentinel; - -import java.util.ArrayList; -import java.util.function.Function; - -import com.alibaba.cloud.circuitbreaker.sentinel.SentinelConfigBuilder.SentinelCircuitBreakerConfiguration; -import com.alibaba.csp.sentinel.EntryType; - -import org.springframework.cloud.client.circuitbreaker.CircuitBreaker; -import org.springframework.cloud.client.circuitbreaker.CircuitBreakerFactory; -import org.springframework.util.Assert; - -/** - * @author Eric Zhao - */ -public class SentinelCircuitBreakerFactory extends - CircuitBreakerFactory { - - private Function defaultConfiguration = id -> new SentinelConfigBuilder() - .resourceName(id).entryType(EntryType.OUT).rules(new ArrayList<>()).build(); - - @Override - public CircuitBreaker create(String id) { - Assert.hasText(id, "A CircuitBreaker must have an id."); - SentinelConfigBuilder.SentinelCircuitBreakerConfiguration conf = getConfigurations() - .computeIfAbsent(id, defaultConfiguration); - return new SentinelCircuitBreaker(id, conf.getEntryType(), conf.getRules()); - } - - @Override - protected SentinelConfigBuilder configBuilder(String id) { - return new SentinelConfigBuilder(id); - } - - @Override - public void configureDefault( - Function defaultConfiguration) { - this.defaultConfiguration = defaultConfiguration; - } - -} diff --git a/spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/SentinelConfigBuilder.java b/spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/SentinelConfigBuilder.java deleted file mode 100644 index b37b5d35..00000000 --- a/spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/main/java/com/alibaba/cloud/circuitbreaker/sentinel/SentinelConfigBuilder.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright 2013-2019 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.circuitbreaker.sentinel; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - -import com.alibaba.csp.sentinel.EntryType; -import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule; - -import org.springframework.cloud.client.circuitbreaker.ConfigBuilder; -import org.springframework.util.Assert; - -/** - * @author Eric Zhao - */ -public class SentinelConfigBuilder implements - ConfigBuilder { - - private String resourceName; - - private EntryType entryType; - - private List rules; - - public SentinelConfigBuilder() { - } - - public SentinelConfigBuilder(String resourceName) { - this.resourceName = resourceName; - } - - public SentinelConfigBuilder resourceName(String resourceName) { - this.resourceName = resourceName; - return this; - } - - public SentinelConfigBuilder entryType(EntryType entryType) { - this.entryType = entryType; - return this; - } - - public SentinelConfigBuilder rules(List rules) { - this.rules = rules; - return this; - } - - @Override - public SentinelCircuitBreakerConfiguration build() { - Assert.hasText(resourceName, "resourceName cannot be empty"); - List rules = Optional.ofNullable(this.rules) - .orElse(new ArrayList<>()); - - EntryType entryType = Optional.ofNullable(this.entryType).orElse(EntryType.OUT); - return new SentinelCircuitBreakerConfiguration() - .setResourceName(this.resourceName).setEntryType(entryType) - .setRules(rules); - } - - public static class SentinelCircuitBreakerConfiguration { - - private String resourceName; - - private EntryType entryType; - - private List rules; - - public String getResourceName() { - return resourceName; - } - - public SentinelCircuitBreakerConfiguration setResourceName(String resourceName) { - this.resourceName = resourceName; - return this; - } - - public EntryType getEntryType() { - return entryType; - } - - public SentinelCircuitBreakerConfiguration setEntryType(EntryType entryType) { - this.entryType = entryType; - return this; - } - - public List getRules() { - return rules; - } - - public SentinelCircuitBreakerConfiguration setRules(List rules) { - this.rules = rules; - return this; - } - - } - -} diff --git a/spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/main/resources/META-INF/additional-spring-configuration-metadata.json deleted file mode 100644 index 44597a6d..00000000 --- a/spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ /dev/null @@ -1,7 +0,0 @@ -{"properties": [ - { - "name": "spring.cloud.circuitbreaker.sentinel.enabled", - "type": "java.lang.Boolean", - "description": "enable sentinel circuitbreaker or not." - } -]} diff --git a/spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/main/resources/META-INF/spring.factories b/spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/main/resources/META-INF/spring.factories deleted file mode 100644 index 1fdc6769..00000000 --- a/spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,3 +0,0 @@ -org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -com.alibaba.cloud.circuitbreaker.sentinel.SentinelCircuitBreakerAutoConfiguration,\ -com.alibaba.cloud.circuitbreaker.sentinel.ReactiveSentinelCircuitBreakerAutoConfiguration \ No newline at end of file diff --git a/spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/test/java/com/alibaba/cloud/circuitbreaker/sentinel/ReactiveSentinelCircuitBreakerIntegrationTest.java b/spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/test/java/com/alibaba/cloud/circuitbreaker/sentinel/ReactiveSentinelCircuitBreakerIntegrationTest.java deleted file mode 100644 index 5d2ed989..00000000 --- a/spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/test/java/com/alibaba/cloud/circuitbreaker/sentinel/ReactiveSentinelCircuitBreakerIntegrationTest.java +++ /dev/null @@ -1,209 +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.circuitbreaker.sentinel; - -import java.time.Duration; -import java.util.Collections; - -import com.alibaba.csp.sentinel.slots.block.RuleConstant; -import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; -import reactor.test.StepVerifier; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.cloud.client.circuitbreaker.Customizer; -import org.springframework.cloud.client.circuitbreaker.ReactiveCircuitBreakerFactory; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.core.ParameterizedTypeReference; -import org.springframework.stereotype.Service; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.reactive.function.client.WebClient; - -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; - -/** - * @author Ryan Baxter - */ -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = RANDOM_PORT, - classes = ReactiveSentinelCircuitBreakerIntegrationTest.Application.class, - properties = { "spring.cloud.discovery.client.health-indicator.enabled=false" }) -@DirtiesContext -public class ReactiveSentinelCircuitBreakerIntegrationTest { - - @LocalServerPort - private int port = 0; - - @Autowired - private ReactiveSentinelCircuitBreakerIntegrationTest.Application.DemoControllerService service; - - @Before - public void setup() { - service.setPort(port); - } - - @Test - public void test() throws Exception { - StepVerifier.create(service.normal()).expectNext("normal").verifyComplete(); - StepVerifier.create(service.slow()).expectNext("slow").verifyComplete(); - StepVerifier.create(service.slow()).expectNext("slow").verifyComplete(); - StepVerifier.create(service.slow()).expectNext("slow").verifyComplete(); - StepVerifier.create(service.slow()).expectNext("slow").verifyComplete(); - StepVerifier.create(service.slow()).expectNext("slow").verifyComplete(); - - // Then in the next 5s, the fallback method should be called. - for (int i = 0; i < 5; i++) { - StepVerifier.create(service.slow()).expectNext("fallback").verifyComplete(); - Thread.sleep(1000); - } - - // Recovered. - StepVerifier.create(service.slow()).expectNext("slow").verifyComplete(); - - StepVerifier.create(service.normalFlux()).expectNext("normalflux") - .verifyComplete(); - StepVerifier.create(service.slowFlux()).expectNext("slowflux").verifyComplete(); - StepVerifier.create(service.slowFlux()).expectNext("slowflux").verifyComplete(); - StepVerifier.create(service.slowFlux()).expectNext("slowflux").verifyComplete(); - StepVerifier.create(service.slowFlux()).expectNext("slowflux").verifyComplete(); - StepVerifier.create(service.slowFlux()).expectNext("slowflux").verifyComplete(); - // Then in the next 5s, the fallback method should be called. - for (int i = 0; i < 5; i++) { - StepVerifier.create(service.slowFlux()).expectNext("flux_fallback") - .verifyComplete(); - Thread.sleep(1000); - } - - // Recovered. - StepVerifier.create(service.slowFlux()).expectNext("slowflux").verifyComplete(); - } - - @Configuration - @EnableAutoConfiguration - @RestController - protected static class Application { - - @GetMapping("/slow") - public Mono slow() { - return Mono.just("slow").delayElement(Duration.ofMillis(500)); - } - - @GetMapping("/normal") - public Mono normal() { - return Mono.just("normal"); - } - - @GetMapping("/slow_flux") - public Flux slowFlux() { - return Flux.just("slow", "flux").delayElements(Duration.ofMillis(500)); - } - - @GetMapping("normal_flux") - public Flux normalFlux() { - return Flux.just("normal", "flux"); - } - - @Bean - public Customizer slowCustomizer() { - return factory -> { - factory.configure(builder -> builder - .rules(Collections.singletonList(new DegradeRule("slow_mono") - .setGrade(RuleConstant.DEGRADE_GRADE_RT).setCount(100) - .setTimeWindow(5))), - "slow_mono"); - factory.configure(builder -> builder - .rules(Collections.singletonList(new DegradeRule("slow_flux") - .setGrade(RuleConstant.DEGRADE_GRADE_RT).setCount(100) - .setTimeWindow(5))), - "slow_flux"); - factory.configureDefault(id -> new SentinelConfigBuilder() - .resourceName(id) - .rules(Collections.singletonList(new DegradeRule(id) - .setGrade(RuleConstant.DEGRADE_GRADE_EXCEPTION_COUNT) - .setCount(0.5).setTimeWindow(10))) - .build()); - }; - } - - @Service - public static class DemoControllerService { - - private int port = 0; - - private ReactiveCircuitBreakerFactory cbFactory; - - DemoControllerService(ReactiveCircuitBreakerFactory cbFactory) { - this.cbFactory = cbFactory; - } - - public Mono slow() { - return WebClient.builder().baseUrl("http://localhost:" + port).build() - .get().uri("/slow").retrieve().bodyToMono(String.class) - .transform(it -> cbFactory.create("slow_mono").run(it, t -> { - t.printStackTrace(); - return Mono.just("fallback"); - })); - } - - public Mono normal() { - return WebClient.builder().baseUrl("http://localhost:" + port).build() - .get().uri("/normal").retrieve().bodyToMono(String.class) - .transform(it -> cbFactory.create("normal_mono").run(it, t -> { - t.printStackTrace(); - return Mono.just("fallback"); - })); - } - - public Flux slowFlux() { - return WebClient.builder().baseUrl("http://localhost:" + port).build() - .get().uri("/slow_flux").retrieve() - .bodyToFlux(new ParameterizedTypeReference() { - }).transform(it -> cbFactory.create("slow_flux").run(it, t -> { - t.printStackTrace(); - return Flux.just("flux_fallback"); - })); - } - - public Flux normalFlux() { - return WebClient.builder().baseUrl("http://localhost:" + port).build() - .get().uri("/normal_flux").retrieve().bodyToFlux(String.class) - .transform(it -> cbFactory.create("normal_flux").run(it, t -> { - t.printStackTrace(); - return Flux.just("flux_fallback"); - })); - } - - public void setPort(int port) { - this.port = port; - } - - } - - } - -} diff --git a/spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/test/java/com/alibaba/cloud/circuitbreaker/sentinel/ReactiveSentinelCircuitBreakerTest.java b/spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/test/java/com/alibaba/cloud/circuitbreaker/sentinel/ReactiveSentinelCircuitBreakerTest.java deleted file mode 100644 index 59d5bcaf..00000000 --- a/spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/test/java/com/alibaba/cloud/circuitbreaker/sentinel/ReactiveSentinelCircuitBreakerTest.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2013-2019 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.circuitbreaker.sentinel; - -import java.util.Arrays; -import java.util.Collections; - -import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRuleManager; -import org.junit.Test; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; - -import org.springframework.cloud.client.circuitbreaker.ReactiveCircuitBreaker; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * @author Eric Zhao - */ -public class ReactiveSentinelCircuitBreakerTest { - - @Test - public void testCreateWithNullRule() { - String id = "testCreateReactiveCbWithNullRule"; - ReactiveSentinelCircuitBreaker cb = new ReactiveSentinelCircuitBreaker(id, - Collections.singletonList(null)); - assertThat(Mono.just("foobar").transform(it -> cb.run(it)).block()) - .isEqualTo("foobar"); - assertThat(DegradeRuleManager.hasConfig(id)).isFalse(); - } - - @Test - public void runMono() { - ReactiveCircuitBreaker cb = new ReactiveSentinelCircuitBreakerFactory() - .create("foo"); - assertThat(Mono.just("foobar").transform(it -> cb.run(it)).block()) - .isEqualTo("foobar"); - } - - @Test - public void runMonoWithFallback() { - ReactiveCircuitBreaker cb = new ReactiveSentinelCircuitBreakerFactory() - .create("foo"); - assertThat(Mono.error(new RuntimeException("boom")) - .transform(it -> cb.run(it, t -> Mono.just("fallback"))).block()) - .isEqualTo("fallback"); - } - - @Test - public void runFlux() { - ReactiveCircuitBreaker cb = new ReactiveSentinelCircuitBreakerFactory() - .create("foo"); - assertThat(Flux.just("foobar", "hello world").transform(it -> cb.run(it)) - .collectList().block()).isEqualTo(Arrays.asList("foobar", "hello world")); - } - - @Test - public void runFluxWithFallback() { - ReactiveCircuitBreaker cb = new ReactiveSentinelCircuitBreakerFactory() - .create("foo"); - assertThat(Flux.error(new RuntimeException("boom")) - .transform(it -> cb.run(it, t -> Flux.just("fallback"))).collectList() - .block()).isEqualTo(Arrays.asList("fallback")); - } - -} diff --git a/spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/test/java/com/alibaba/cloud/circuitbreaker/sentinel/SentinelCircuitBreakerIntegrationTest.java b/spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/test/java/com/alibaba/cloud/circuitbreaker/sentinel/SentinelCircuitBreakerIntegrationTest.java deleted file mode 100644 index d63abfb5..00000000 --- a/spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/test/java/com/alibaba/cloud/circuitbreaker/sentinel/SentinelCircuitBreakerIntegrationTest.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright 2013-2019 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.circuitbreaker.sentinel; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import com.alibaba.csp.sentinel.slots.block.RuleConstant; -import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule; -import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRuleManager; -import org.junit.Before; -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.test.context.SpringBootTest; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.cloud.client.circuitbreaker.CircuitBreakerFactory; -import org.springframework.cloud.client.circuitbreaker.Customizer; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.stereotype.Service; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; - -/** - * @author Eric Zhao - */ -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = RANDOM_PORT, - classes = SentinelCircuitBreakerIntegrationTest.Application.class, - properties = { "spring.cloud.discovery.client.health-indicator.enabled=false" }) -@DirtiesContext -public class SentinelCircuitBreakerIntegrationTest { - - @Autowired - private Application.DemoControllerService service; - - @Test - public void testSlow() throws Exception { - // The first 5 requests should pass. - assertThat(service.slow()).isEqualTo("slow"); - assertThat(service.slow()).isEqualTo("slow"); - assertThat(service.slow()).isEqualTo("slow"); - assertThat(service.slow()).isEqualTo("slow"); - assertThat(service.slow()).isEqualTo("slow"); - - // Then in the next 10s, the fallback method should be called. - for (int i = 0; i < 10; i++) { - assertThat(service.slow()).isEqualTo("fallback"); - Thread.sleep(1000); - } - - // Recovered. - assertThat(service.slow()).isEqualTo("slow"); - } - - @Test - public void testNormal() { - assertThat(service.normal()).isEqualTo("normal"); - } - - @Before - public void setUp() { - DegradeRuleManager.loadRules(new ArrayList<>()); - } - - @Before - public void tearDown() { - DegradeRuleManager.loadRules(new ArrayList<>()); - } - - @Configuration - @EnableAutoConfiguration - @RestController - protected static class Application { - - @GetMapping("/slow") - public String slow() throws InterruptedException { - Thread.sleep(500); - return "slow"; - } - - @GetMapping("/normal") - public String normal() { - return "normal"; - } - - @Bean - public Customizer slowCustomizer() { - String slowId = "slow"; - List rules = Collections.singletonList( - new DegradeRule(slowId).setGrade(RuleConstant.DEGRADE_GRADE_RT) - .setCount(100).setTimeWindow(10)); - return factory -> { - factory.configure(builder -> builder.rules(rules), slowId); - factory.configureDefault(id -> new SentinelConfigBuilder() - .resourceName(id) - .rules(Collections.singletonList(new DegradeRule(id) - .setGrade(RuleConstant.DEGRADE_GRADE_EXCEPTION_COUNT) - .setCount(0.5).setTimeWindow(10))) - .build()); - }; - } - - @Service - public static class DemoControllerService { - - private TestRestTemplate rest; - - private CircuitBreakerFactory cbFactory; - - DemoControllerService(TestRestTemplate rest, - CircuitBreakerFactory cbFactory) { - this.rest = rest; - this.cbFactory = cbFactory; - } - - public String slow() { - return cbFactory.create("slow").run( - () -> rest.getForObject("/slow", String.class), t -> "fallback"); - } - - public String normal() { - return cbFactory.create("normal").run( - () -> rest.getForObject("/normal", String.class), - t -> "fallback"); - } - - } - - } - -} diff --git a/spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/test/java/com/alibaba/cloud/circuitbreaker/sentinel/SentinelCircuitBreakerTest.java b/spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/test/java/com/alibaba/cloud/circuitbreaker/sentinel/SentinelCircuitBreakerTest.java deleted file mode 100644 index 439d15c7..00000000 --- a/spring-cloud-alibaba-starters/spring-cloud-circuitbreaker-sentinel/src/test/java/com/alibaba/cloud/circuitbreaker/sentinel/SentinelCircuitBreakerTest.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2013-2019 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.circuitbreaker.sentinel; - -import java.util.ArrayList; -import java.util.Collections; - -import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule; -import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRuleManager; -import org.junit.After; -import org.junit.Test; - -import org.springframework.cloud.client.circuitbreaker.CircuitBreaker; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * @author Eric Zhao - */ -public class SentinelCircuitBreakerTest { - - @After - public void tearDown() { - // Clear the rules. - DegradeRuleManager.loadRules(new ArrayList<>()); - } - - @Test - public void testCreateDirectlyThenRun() { - // Create a circuit breaker without any circuit breaking rules. - CircuitBreaker cb = new SentinelCircuitBreaker( - "testSentinelCreateDirectlyThenRunA"); - assertThat(cb.run(() -> "Sentinel")).isEqualTo("Sentinel"); - assertThat(DegradeRuleManager.hasConfig("testSentinelCreateDirectlyThenRunA")) - .isFalse(); - - CircuitBreaker cb2 = new SentinelCircuitBreaker( - "testSentinelCreateDirectlyThenRunB", - Collections.singletonList( - new DegradeRule("testSentinelCreateDirectlyThenRunB") - .setCount(100).setTimeWindow(10))); - assertThat(cb2.run(() -> "Sentinel")).isEqualTo("Sentinel"); - assertThat(DegradeRuleManager.hasConfig("testSentinelCreateDirectlyThenRunB")) - .isTrue(); - } - - @Test - public void testCreateWithNullRule() { - String id = "testCreateCbWithNullRule"; - CircuitBreaker cb = new SentinelCircuitBreaker(id, - Collections.singletonList(null)); - assertThat(cb.run(() -> "Sentinel")).isEqualTo("Sentinel"); - assertThat(DegradeRuleManager.hasConfig(id)).isFalse(); - } - - @Test - public void testCreateFromFactoryThenRun() { - CircuitBreaker cb = new SentinelCircuitBreakerFactory().create("testSentinelRun"); - assertThat(cb.run(() -> "foobar")).isEqualTo("foobar"); - } - - @Test - public void testRunWithFallback() { - CircuitBreaker cb = new SentinelCircuitBreakerFactory() - .create("testSentinelRunWithFallback"); - assertThat(cb.run(() -> { - throw new RuntimeException("boom"); - }, t -> "fallback")).isEqualTo("fallback"); - } - -} 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 6e75c8db..678e0063 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 @@ -131,6 +131,20 @@ 2.0.0 test + + + org.junit.jupiter + junit-jupiter + 5.5.2 + compile + + + + org.mockito + mockito-junit-jupiter + 3.1.0 + compile + diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/discovery/NacosDiscoveryClientConfiguration.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/discovery/NacosDiscoveryClientConfiguration.java index f2453f41..893b9e69 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/discovery/NacosDiscoveryClientConfiguration.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/discovery/NacosDiscoveryClientConfiguration.java @@ -25,7 +25,6 @@ import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.cloud.client.CommonsClientAutoConfiguration; -import org.springframework.cloud.client.ConditionalOnBlockingDiscoveryEnabled; import org.springframework.cloud.client.ConditionalOnDiscoveryEnabled; import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.cloud.client.discovery.simple.SimpleDiscoveryClientAutoConfiguration; @@ -39,7 +38,9 @@ import org.springframework.scheduling.TaskScheduler; */ @Configuration @ConditionalOnDiscoveryEnabled -@ConditionalOnBlockingDiscoveryEnabled +//@ConditionalOnBlockingDiscoveryEnabled +@ConditionalOnProperty(value = "spring.cloud.discovery.blocking.enabled", + matchIfMissing = true) @ConditionalOnNacosDiscoveryEnabled @AutoConfigureBefore({ SimpleDiscoveryClientAutoConfiguration.class, CommonsClientAutoConfiguration.class }) diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/discovery/configclient/NacosDiscoveryClientConfigServiceBootstrapConfiguration.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/discovery/configclient/NacosDiscoveryClientConfigServiceBootstrapConfiguration.java index 73a01d93..08ab5c12 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/discovery/configclient/NacosDiscoveryClientConfigServiceBootstrapConfiguration.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/discovery/configclient/NacosDiscoveryClientConfigServiceBootstrapConfiguration.java @@ -18,7 +18,6 @@ package com.alibaba.cloud.nacos.discovery.configclient; import com.alibaba.cloud.nacos.discovery.NacosDiscoveryAutoConfiguration; import com.alibaba.cloud.nacos.discovery.NacosDiscoveryClientConfiguration; -import com.alibaba.cloud.nacos.discovery.reactive.NacosReactiveDiscoveryClientConfiguration; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -36,8 +35,7 @@ import org.springframework.context.annotation.Configuration; matchIfMissing = false) @Configuration @ImportAutoConfiguration({ NacosDiscoveryAutoConfiguration.class, - NacosDiscoveryClientConfiguration.class, - NacosReactiveDiscoveryClientConfiguration.class }) + NacosDiscoveryClientConfiguration.class}) public class NacosDiscoveryClientConfigServiceBootstrapConfiguration { } diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/discovery/reactive/NacosReactiveDiscoveryClient.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/discovery/reactive/NacosReactiveDiscoveryClient.java deleted file mode 100644 index d01731a6..00000000 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/discovery/reactive/NacosReactiveDiscoveryClient.java +++ /dev/null @@ -1,84 +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.discovery.reactive; - -import java.util.function.Function; - -import com.alibaba.cloud.nacos.discovery.NacosServiceDiscovery; -import com.alibaba.nacos.api.exception.NacosException; -import org.reactivestreams.Publisher; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; -import reactor.core.scheduler.Schedulers; - -import org.springframework.cloud.client.ServiceInstance; -import org.springframework.cloud.client.discovery.ReactiveDiscoveryClient; - -/** - * @author echooymxq - **/ -public class NacosReactiveDiscoveryClient implements ReactiveDiscoveryClient { - - private static final Logger log = LoggerFactory - .getLogger(NacosReactiveDiscoveryClient.class); - - private NacosServiceDiscovery serviceDiscovery; - - public NacosReactiveDiscoveryClient(NacosServiceDiscovery nacosServiceDiscovery) { - this.serviceDiscovery = nacosServiceDiscovery; - } - - @Override - public String description() { - return "Spring Cloud Nacos Reactive Discovery Client"; - } - - @Override - public Flux getInstances(String serviceId) { - - return Mono.justOrEmpty(serviceId).flatMapMany(loadInstancesFromNacos()) - .subscribeOn(Schedulers.boundedElastic()); - } - - private Function> loadInstancesFromNacos() { - return serviceId -> { - try { - return Flux.fromIterable(serviceDiscovery.getInstances(serviceId)); - } - catch (NacosException e) { - log.error("get service instance[{}] from nacos error!", serviceId, e); - return Flux.empty(); - } - }; - } - - @Override - public Flux getServices() { - return Flux.defer(() -> { - try { - return Flux.fromIterable(serviceDiscovery.getServices()); - } - catch (Exception e) { - log.error("get services from nacos server fail,", e); - return Flux.empty(); - } - }).subscribeOn(Schedulers.boundedElastic()); - } - -} diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/discovery/reactive/NacosReactiveDiscoveryClientConfiguration.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/discovery/reactive/NacosReactiveDiscoveryClientConfiguration.java deleted file mode 100644 index 96c32767..00000000 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/discovery/reactive/NacosReactiveDiscoveryClientConfiguration.java +++ /dev/null @@ -1,52 +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.discovery.reactive; - -import com.alibaba.cloud.nacos.ConditionalOnNacosDiscoveryEnabled; -import com.alibaba.cloud.nacos.discovery.NacosDiscoveryAutoConfiguration; -import com.alibaba.cloud.nacos.discovery.NacosServiceDiscovery; - -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.AutoConfigureBefore; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.cloud.client.ConditionalOnDiscoveryEnabled; -import org.springframework.cloud.client.ConditionalOnReactiveDiscoveryEnabled; -import org.springframework.cloud.client.ReactiveCommonsClientAutoConfiguration; -import org.springframework.cloud.client.discovery.composite.reactive.ReactiveCompositeDiscoveryClientAutoConfiguration; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * @author echooymxq - **/ -@Configuration -@ConditionalOnDiscoveryEnabled -@ConditionalOnReactiveDiscoveryEnabled -@ConditionalOnNacosDiscoveryEnabled -@AutoConfigureAfter({ NacosDiscoveryAutoConfiguration.class, - ReactiveCompositeDiscoveryClientAutoConfiguration.class }) -@AutoConfigureBefore({ ReactiveCommonsClientAutoConfiguration.class }) -public class NacosReactiveDiscoveryClientConfiguration { - - @Bean - @ConditionalOnMissingBean - public NacosReactiveDiscoveryClient nacosReactiveDiscoveryClient( - NacosServiceDiscovery nacosServiceDiscovery) { - return new NacosReactiveDiscoveryClient(nacosServiceDiscovery); - } - -} 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 6189df59..c7a516de 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 @@ -4,7 +4,6 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ com.alibaba.cloud.nacos.endpoint.NacosDiscoveryEndpointAutoConfiguration,\ com.alibaba.cloud.nacos.registry.NacosServiceRegistryAutoConfiguration,\ com.alibaba.cloud.nacos.discovery.NacosDiscoveryClientConfiguration,\ - com.alibaba.cloud.nacos.discovery.reactive.NacosReactiveDiscoveryClientConfiguration,\ com.alibaba.cloud.nacos.discovery.configclient.NacosConfigServerAutoConfiguration org.springframework.cloud.bootstrap.BootstrapConfiguration=\ com.alibaba.cloud.nacos.discovery.configclient.NacosDiscoveryClientConfigServiceBootstrapConfiguration diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/discovery/reactive/NacosReactiveDiscoveryClientConfigurationTests.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/discovery/reactive/NacosReactiveDiscoveryClientConfigurationTests.java deleted file mode 100644 index 9700581e..00000000 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/discovery/reactive/NacosReactiveDiscoveryClientConfigurationTests.java +++ /dev/null @@ -1,45 +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.discovery.reactive; - -import com.alibaba.cloud.nacos.discovery.NacosDiscoveryAutoConfiguration; -import org.junit.jupiter.api.Test; - -import org.springframework.boot.autoconfigure.AutoConfigurations; -import org.springframework.boot.test.context.runner.ApplicationContextRunner; -import org.springframework.cloud.client.discovery.ReactiveDiscoveryClient; -import org.springframework.cloud.commons.util.UtilAutoConfiguration; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * @author echooymxq - **/ -public class NacosReactiveDiscoveryClientConfigurationTests { - - private ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .withConfiguration(AutoConfigurations.of(UtilAutoConfiguration.class, - NacosDiscoveryAutoConfiguration.class, - NacosReactiveDiscoveryClientConfiguration.class)); - - @Test - public void testDefaultInitialization() { - contextRunner.run(context -> assertThat(context) - .hasSingleBean(ReactiveDiscoveryClient.class)); - } - -} diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/discovery/reactive/NacosReactiveDiscoveryClientTests.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/discovery/reactive/NacosReactiveDiscoveryClientTests.java deleted file mode 100644 index ff474fdc..00000000 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/test/java/com/alibaba/cloud/nacos/discovery/reactive/NacosReactiveDiscoveryClientTests.java +++ /dev/null @@ -1,74 +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.discovery.reactive; - -import java.util.Arrays; - -import com.alibaba.cloud.nacos.discovery.NacosServiceDiscovery; -import com.alibaba.nacos.api.exception.NacosException; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; -import reactor.core.publisher.Flux; -import reactor.test.StepVerifier; - -import org.springframework.cloud.client.ServiceInstance; - -import static java.util.Collections.singletonList; -import static org.mockito.Mockito.when; - -/** - * @author echooymxq - **/ -@ExtendWith(MockitoExtension.class) -class NacosReactiveDiscoveryClientTests { - - @Mock - private NacosServiceDiscovery serviceDiscovery; - - @Mock - private ServiceInstance serviceInstance; - - @InjectMocks - private NacosReactiveDiscoveryClient client; - - @Test - void testGetInstances() throws NacosException { - - when(serviceDiscovery.getInstances("reactive-service")) - .thenReturn(singletonList(serviceInstance)); - - Flux instances = this.client.getInstances("reactive-service"); - - StepVerifier.create(instances).expectNextCount(1).expectComplete().verify(); - } - - @Test - void testGetServices() throws NacosException { - - when(serviceDiscovery.getServices()) - .thenReturn(Arrays.asList("reactive-service1", "reactive-service2")); - - Flux services = this.client.getServices(); - - StepVerifier.create(services).expectNext("reactive-service1", "reactive-service2") - .expectComplete().verify(); - } - -} 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 90033cd3..cb87e4e6 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 @@ -86,12 +86,6 @@ true - - - - - - org.springframework.cloud spring-cloud-starter-netflix-ribbon 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 deleted file mode 100644 index b504ccc8..00000000 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignBlockingLoadBalancerClient.java +++ /dev/null @@ -1,45 +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.loadbalancer.blocking.client.BlockingLoadBalancerClient; -import org.springframework.cloud.openfeign.loadbalancer.FeignBlockingLoadBalancerClient; - -/** - * @author yuhuangbin - */ -public class SeataFeignBlockingLoadBalancerClient - extends FeignBlockingLoadBalancerClient { - - public SeataFeignBlockingLoadBalancerClient(Client delegate, - BlockingLoadBalancerClient loadBalancerClient, - SeataFeignObjectWrapper seataFeignObjectWrapper) { - super((Client) seataFeignObjectWrapper.wrap(delegate), loadBalancerClient); - } - - @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/SeataFeignObjectWrapper.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-seata/src/main/java/com/alibaba/cloud/seata/feign/SeataFeignObjectWrapper.java index ae505058..431d654e 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,9 +21,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.BeanFactory; -import org.springframework.cloud.loadbalancer.blocking.client.BlockingLoadBalancerClient; import org.springframework.cloud.netflix.ribbon.SpringClientFactory; -import org.springframework.cloud.openfeign.loadbalancer.FeignBlockingLoadBalancerClient; import org.springframework.cloud.openfeign.ribbon.CachingSpringLoadBalancerFactory; import org.springframework.cloud.openfeign.ribbon.LoadBalancerFeignClient; @@ -51,11 +49,6 @@ public class SeataFeignObjectWrapper { 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); - } return new SeataFeignClient(this.beanFactory, (Client) bean); } return bean; 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 dcacddfa..8294c17b 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 @@ -103,11 +103,6 @@ true - - com.alibaba.cloud - spring-cloud-circuitbreaker-sentinel - - com.alibaba.csp sentinel-apache-dubbo-adapter diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/endpoint/SentinelHealthIndicator.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/endpoint/SentinelHealthIndicator.java index 2d9466b3..74bdf075 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/endpoint/SentinelHealthIndicator.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/endpoint/SentinelHealthIndicator.java @@ -74,7 +74,7 @@ public class SentinelHealthIndicator extends AbstractHealthIndicator { // detail if (!sentinelProperties.isEnabled()) { detailMap.put("enabled", false); - builder.up().withDetails(detailMap); + withDetails(builder.up(), detailMap); return; } @@ -139,11 +139,16 @@ public class SentinelHealthIndicator extends AbstractHealthIndicator { // If Dashboard and DataSource are both OK, the health status is UP if (dashboardUp && dataSourceUp) { - builder.up().withDetails(detailMap); + withDetails(builder.up(), detailMap); } else { - builder.down().withDetails(detailMap); + withDetails(builder.down(), detailMap); } } + private void withDetails(Health.Builder builder, Map detailMap) { + for (String key : detailMap.keySet()) { + builder.withDetail(key, detailMap.get(key)); + } + } } diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/feign/SentinelContractHolder.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/feign/SentinelContractHolder.java index 4c16165d..9a5acfd3 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/feign/SentinelContractHolder.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/feign/SentinelContractHolder.java @@ -45,8 +45,8 @@ public class SentinelContractHolder implements Contract { } @Override - public List parseAndValidateMetadata(Class targetType) { - List metadatas = delegate.parseAndValidateMetadata(targetType); + public List parseAndValidatateMetadata(Class targetType) { + List metadatas = delegate.parseAndValidatateMetadata(targetType); metadatas.forEach(metadata -> METADATA_MAP .put(targetType.getName() + metadata.configKey(), metadata)); return metadatas; 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..f6af13fe 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 @@ -33,7 +33,6 @@ import org.springframework.cloud.openfeign.FeignContext; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.util.ReflectionUtils; -import org.springframework.util.StringUtils; /** * {@link Feign.Builder} like {@link HystrixFeign.Builder}. @@ -87,11 +86,7 @@ public final class SentinelFeign { "fallback"); Class fallbackFactory = (Class) getFieldValue(feignClientFactoryBean, "fallbackFactory"); - String beanName = (String) getFieldValue(feignClientFactoryBean, - "contextId"); - if (!StringUtils.hasText(beanName)) { - beanName = (String) getFieldValue(feignClientFactoryBean, "name"); - } + String beanName = (String) getFieldValue(feignClientFactoryBean, "name"); Object fallbackInstance; FallbackFactory fallbackFactoryInstance; 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..8c2eb550 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 @@ -99,7 +99,7 @@ public class SentinelInvocationHandler implements InvocationHandler { } else { String resourceName = methodMetadata.template().method().toUpperCase() - + ":" + hardCodedTarget.url() + methodMetadata.template().path(); + + ":" + hardCodedTarget.url() + methodMetadata.template().url(); Entry entry = null; try { ContextUtil.enter(resourceName); 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..2066ba49 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 @@ -1,136 +1,136 @@ -/* - * 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; - -import com.alibaba.cloud.sentinel.feign.SentinelFeignAutoConfiguration; -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.test.context.SpringBootTest; -import org.springframework.cloud.openfeign.EnableFeignClients; -import org.springframework.cloud.openfeign.FeignClient; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Add this unit test to verify https://github.com/alibaba/spring-cloud-alibaba/pull/838. - * - * @author Jim - */ -@RunWith(SpringRunner.class) -@SpringBootTest(classes = { ContextIdSentinelFeignTests.TestConfig.class }, - properties = { "feign.sentinel.enabled=true" }) -public class ContextIdSentinelFeignTests { - - @Autowired - private EchoService echoService; - - @Autowired - private FooService fooService; - - @Test - public void testFeignClient() { - assertThat(echoService.echo("test")).isEqualTo("echo fallback"); - assertThat(fooService.echo("test")).isEqualTo("foo fallback"); - assertThat(fooService.toString()).isNotEqualTo(echoService.toString()); - assertThat(fooService.hashCode()).isNotEqualTo(echoService.hashCode()); - assertThat(echoService.equals(fooService)).isEqualTo(Boolean.FALSE); - } - - @Configuration - @EnableAutoConfiguration - @ImportAutoConfiguration({ SentinelFeignAutoConfiguration.class }) - @EnableFeignClients - public static class TestConfig { - - } - - @FeignClient(contextId = "echoService", name = "service-provider", - fallback = EchoServiceFallback.class, - configuration = FeignConfiguration.class) - public interface EchoService { - - @GetMapping("/echo/{str}") - String echo(@PathVariable("str") String str); - - } - - @FeignClient(contextId = "fooService", value = "foo-service", - fallbackFactory = CustomFallbackFactory.class, - configuration = FeignConfiguration.class) - public interface FooService { - - @RequestMapping(path = "echo/{str}") - String echo(@RequestParam("str") String param); - - } - - public static class FeignConfiguration { - - @Bean - public EchoServiceFallback echoServiceFallback() { - return new EchoServiceFallback(); - } - - @Bean - public CustomFallbackFactory customFallbackFactory() { - return new CustomFallbackFactory(); - } - - } - - public static class EchoServiceFallback implements EchoService { - - @Override - public String echo(@RequestParam("str") String param) { - return "echo fallback"; - } - - } - - public static class FooServiceFallback implements FooService { - - @Override - public String echo(@RequestParam("str") String param) { - return "foo fallback"; - } - - } - - public static class CustomFallbackFactory - implements feign.hystrix.FallbackFactory { - - private FooService fooService = new FooServiceFallback(); - - @Override - public FooService create(Throwable throwable) { - return fooService; - } - - } - -} +///* +// * 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; +// +//import com.alibaba.cloud.sentinel.feign.SentinelFeignAutoConfiguration; +//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.test.context.SpringBootTest; +//import org.springframework.cloud.openfeign.EnableFeignClients; +//import org.springframework.cloud.openfeign.FeignClient; +//import org.springframework.context.annotation.Bean; +//import org.springframework.context.annotation.Configuration; +//import org.springframework.test.context.junit4.SpringRunner; +//import org.springframework.web.bind.annotation.GetMapping; +//import org.springframework.web.bind.annotation.PathVariable; +//import org.springframework.web.bind.annotation.RequestMapping; +//import org.springframework.web.bind.annotation.RequestParam; +// +//import static org.assertj.core.api.Assertions.assertThat; +// +///** +// * Add this unit test to verify https://github.com/alibaba/spring-cloud-alibaba/pull/838. +// * +// * @author Jim +// */ +//@RunWith(SpringRunner.class) +//@SpringBootTest(classes = { ContextIdSentinelFeignTests.TestConfig.class }, +// properties = { "feign.sentinel.enabled=true" }) +//public class ContextIdSentinelFeignTests { +// +// @Autowired +// private EchoService echoService; +// +// @Autowired +// private FooService fooService; +// +// @Test +// public void testFeignClient() { +// assertThat(echoService.echo("test")).isEqualTo("echo fallback"); +// assertThat(fooService.echo("test")).isEqualTo("foo fallback"); +// assertThat(fooService.toString()).isNotEqualTo(echoService.toString()); +// assertThat(fooService.hashCode()).isNotEqualTo(echoService.hashCode()); +// assertThat(echoService.equals(fooService)).isEqualTo(Boolean.FALSE); +// } +// +// @Configuration +// @EnableAutoConfiguration +// @ImportAutoConfiguration({ SentinelFeignAutoConfiguration.class }) +// @EnableFeignClients +// public static class TestConfig { +// +// } +// +// @FeignClient(name = "service-provider", +// fallback = EchoServiceFallback.class, +// configuration = FeignConfiguration.class) +// public interface EchoService { +// +// @GetMapping("/echo/{str}") +// String echo(@PathVariable("str") String str); +// +// } +// +// @FeignClient(value = "foo-service", +// fallbackFactory = CustomFallbackFactory.class, +// configuration = FeignConfiguration.class) +// public interface FooService { +// +// @RequestMapping(path = "echo/{str}") +// String echo(@RequestParam("str") String param); +// +// } +// +// public static class FeignConfiguration { +// +// @Bean +// public EchoServiceFallback echoServiceFallback() { +// return new EchoServiceFallback(); +// } +// +// @Bean +// public CustomFallbackFactory customFallbackFactory() { +// return new CustomFallbackFactory(); +// } +// +// } +// +// public static class EchoServiceFallback implements EchoService { +// +// @Override +// public String echo(@RequestParam("str") String param) { +// return "echo fallback"; +// } +// +// } +// +// public static class FooServiceFallback implements FooService { +// +// @Override +// public String echo(@RequestParam("str") String param) { +// return "foo fallback"; +// } +// +// } +// +// public static class CustomFallbackFactory +// implements feign.hystrix.FallbackFactory { +// +// private FooService fooService = new FooServiceFallback(); +// +// @Override +// public FooService create(Throwable throwable) { +// return fooService; +// } +// +// } +// +//} diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/consul/SidecarConsulAutoConfiguration.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/consul/SidecarConsulAutoConfiguration.java index d3f40929..3789f440 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/consul/SidecarConsulAutoConfiguration.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sidecar/src/main/java/com/alibaba/cloud/sidecar/consul/SidecarConsulAutoConfiguration.java @@ -30,7 +30,6 @@ import org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties; import org.springframework.cloud.consul.discovery.HeartbeatProperties; import org.springframework.cloud.consul.serviceregistry.ConsulAutoRegistration; import org.springframework.cloud.consul.serviceregistry.ConsulAutoServiceRegistrationAutoConfiguration; -import org.springframework.cloud.consul.serviceregistry.ConsulManagementRegistrationCustomizer; import org.springframework.cloud.consul.serviceregistry.ConsulRegistrationCustomizer; import org.springframework.cloud.consul.serviceregistry.ConsulServiceRegistry; import org.springframework.cloud.consul.serviceregistry.ConsulServiceRegistryAutoConfiguration; @@ -52,13 +51,12 @@ public class SidecarConsulAutoConfiguration { AutoServiceRegistrationProperties autoServiceRegistrationProperties, ConsulDiscoveryProperties properties, ApplicationContext applicationContext, ObjectProvider> registrationCustomizers, - ObjectProvider> managementRegistrationCustomizers, HeartbeatProperties heartbeatProperties, SidecarProperties sidecarProperties) { return SidecarConsulAutoRegistration.registration( autoServiceRegistrationProperties, properties, applicationContext, registrationCustomizers.getIfAvailable(), - managementRegistrationCustomizers.getIfAvailable(), heartbeatProperties, + heartbeatProperties, sidecarProperties); } 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..fa9d3642 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 @@ -25,7 +25,6 @@ import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationP import org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties; import org.springframework.cloud.consul.discovery.HeartbeatProperties; import org.springframework.cloud.consul.serviceregistry.ConsulAutoRegistration; -import org.springframework.cloud.consul.serviceregistry.ConsulManagementRegistrationCustomizer; import org.springframework.cloud.consul.serviceregistry.ConsulRegistrationCustomizer; import org.springframework.context.ApplicationContext; import org.springframework.core.env.Environment; @@ -38,17 +37,15 @@ public class SidecarConsulAutoRegistration extends ConsulAutoRegistration { public SidecarConsulAutoRegistration(NewService service, AutoServiceRegistrationProperties autoServiceRegistrationProperties, ConsulDiscoveryProperties properties, ApplicationContext context, - HeartbeatProperties heartbeatProperties, - List managementRegistrationCustomizers) { + HeartbeatProperties heartbeatProperties) { super(service, autoServiceRegistrationProperties, properties, context, - heartbeatProperties, managementRegistrationCustomizers); + heartbeatProperties); } public static ConsulAutoRegistration registration( AutoServiceRegistrationProperties autoServiceRegistrationProperties, ConsulDiscoveryProperties properties, ApplicationContext context, List registrationCustomizers, - List managementRegistrationCustomizers, HeartbeatProperties heartbeatProperties, SidecarProperties sidecarProperties) { @@ -72,7 +69,7 @@ public class SidecarConsulAutoRegistration extends ConsulAutoRegistration { ConsulAutoRegistration registration = new ConsulAutoRegistration(service, autoServiceRegistrationProperties, properties, context, - heartbeatProperties, managementRegistrationCustomizers); + heartbeatProperties); customize(registrationCustomizers, registration); return registration; } diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/resolver/DubboServiceBeanMetadataResolver.java b/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/resolver/DubboServiceBeanMetadataResolver.java index 9613e99c..f16c3493 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/resolver/DubboServiceBeanMetadataResolver.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/resolver/DubboServiceBeanMetadataResolver.java @@ -141,7 +141,7 @@ public class DubboServiceBeanMetadataResolver Class targetType) { List methodMetadataList = Collections.emptyList(); try { - methodMetadataList = contract.parseAndValidateMetadata(targetType); + methodMetadataList = contract.parseAndValidatateMetadata(targetType); } catch (Throwable ignored) { // ignore @@ -153,7 +153,7 @@ public class DubboServiceBeanMetadataResolver * Select feign contract methods *

* extract some code from - * {@link Contract.BaseContract#parseAndValidateMetadata(Class)}. + * {@link Contract.BaseContract#parseAndValidatateMetadata(Class)}. * @param targetType class of type * @return non-null */ diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/resolver/DubboTransportedMethodMetadataResolver.java b/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/resolver/DubboTransportedMethodMetadataResolver.java index 2dc19461..b5834adb 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/resolver/DubboTransportedMethodMetadataResolver.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-dubbo/src/main/java/com/alibaba/cloud/dubbo/metadata/resolver/DubboTransportedMethodMetadataResolver.java @@ -90,7 +90,7 @@ public class DubboTransportedMethodMetadataResolver { private Map resolveRestRequestMetadataMap( Class targetType) { - return contract.parseAndValidateMetadata(targetType).stream().collect(Collectors + return contract.parseAndValidatateMetadata(targetType).stream().collect(Collectors .toMap(feign.MethodMetadata::configKey, this::restMethodMetadata)); } diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-stream-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/RocketMQMessageChannelBinder.java b/spring-cloud-alibaba-starters/spring-cloud-starter-stream-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/RocketMQMessageChannelBinder.java index b46acc9c..e3913c34 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-stream-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/RocketMQMessageChannelBinder.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-stream-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/RocketMQMessageChannelBinder.java @@ -46,17 +46,14 @@ import org.apache.rocketmq.spring.core.RocketMQTemplate; import org.apache.rocketmq.spring.support.RocketMQUtil; import org.springframework.cloud.stream.binder.AbstractMessageChannelBinder; -import org.springframework.cloud.stream.binder.BinderSpecificPropertiesProvider; import org.springframework.cloud.stream.binder.ExtendedConsumerProperties; import org.springframework.cloud.stream.binder.ExtendedProducerProperties; import org.springframework.cloud.stream.binder.ExtendedPropertiesBinder; -import org.springframework.cloud.stream.binding.MessageConverterConfigurer; import org.springframework.cloud.stream.provisioning.ConsumerDestination; import org.springframework.cloud.stream.provisioning.ProducerDestination; -import org.springframework.integration.StaticMessageHeaderAccessor; -import org.springframework.integration.acks.AcknowledgmentCallback; -import org.springframework.integration.acks.AcknowledgmentCallback.Status; -import org.springframework.integration.channel.AbstractMessageChannel; +import org.springframework.integration.support.StaticMessageHeaderAccessor; +import org.springframework.integration.support.AcknowledgmentCallback; +import org.springframework.integration.support.AcknowledgmentCallback.Status; import org.springframework.integration.core.MessageProducer; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessageHandler; @@ -71,12 +68,9 @@ public class RocketMQMessageChannelBinder extends implements ExtendedPropertiesBinder { - private RocketMQExtendedBindingProperties extendedBindingProperties = new RocketMQExtendedBindingProperties(); - + private RocketMQExtendedBindingProperties extendedBindingProperties; private final RocketMQBinderConfigurationProperties rocketBinderConfigurationProperties; - private final RocketMQProperties rocketMQProperties; - private final InstrumentationManager instrumentationManager; private Map topicInUse = new HashMap<>(); @@ -96,7 +90,7 @@ public class RocketMQMessageChannelBinder extends @Override protected MessageHandler createProducerMessageHandler(ProducerDestination destination, ExtendedProducerProperties producerProperties, - MessageChannel channel, MessageChannel errorChannel) throws Exception { + MessageChannel errorChannel) throws Exception { if (producerProperties.getExtension().getEnabled()) { // if producerGroup is empty, using destination @@ -168,11 +162,7 @@ public class RocketMQMessageChannelBinder extends RocketMQMessageHandler messageHandler = new RocketMQMessageHandler( rocketMQTemplate, destination.getName(), producerGroup, producerProperties.getExtension().getTransactional(), - instrumentationManager, producerProperties, - ((AbstractMessageChannel) channel).getChannelInterceptors().stream() - .filter(channelInterceptor -> channelInterceptor instanceof MessageConverterConfigurer.PartitioningInterceptor) - .map(channelInterceptor -> ((MessageConverterConfigurer.PartitioningInterceptor) channelInterceptor)) - .findFirst().orElse(null)); + instrumentationManager, producerProperties); messageHandler.setBeanFactory(this.getApplicationContext().getBeanFactory()); messageHandler.setSync(producerProperties.getExtension().getSync()); messageHandler.setHeaderMapper(createHeaderMapper(producerProperties)); @@ -187,14 +177,6 @@ public class RocketMQMessageChannelBinder extends } } - @Override - protected MessageHandler createProducerMessageHandler(ProducerDestination destination, - ExtendedProducerProperties producerProperties, - MessageChannel errorChannel) throws Exception { - throw new UnsupportedOperationException( - "The abstract binder should not call this method"); - } - @Override protected MessageProducer createConsumerEndpoint(ConsumerDestination destination, String group, @@ -286,16 +268,6 @@ public class RocketMQMessageChannelBinder extends return topicInUse; } - @Override - public String getDefaultsPrefix() { - return extendedBindingProperties.getDefaultsPrefix(); - } - - @Override - public Class getExtendedPropertiesEntryClass() { - return extendedBindingProperties.getExtendedPropertiesEntryClass(); - } - public void setExtendedBindingProperties( RocketMQExtendedBindingProperties extendedBindingProperties) { this.extendedBindingProperties = extendedBindingProperties; 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..18dc7f68 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 @@ -38,7 +38,6 @@ import org.slf4j.LoggerFactory; import org.springframework.cloud.stream.binder.BinderHeaders; import org.springframework.cloud.stream.binder.ExtendedProducerProperties; -import org.springframework.cloud.stream.binding.MessageConverterConfigurer; import org.springframework.context.Lifecycle; import org.springframework.integration.handler.AbstractMessageHandler; import org.springframework.integration.support.DefaultErrorMessageStrategy; @@ -81,20 +80,16 @@ public class RocketMQMessageHandler extends AbstractMessageHandler implements Li private ExtendedProducerProperties producerProperties; - private MessageConverterConfigurer.PartitioningInterceptor partitioningInterceptor; - public RocketMQMessageHandler(RocketMQTemplate rocketMQTemplate, String destination, String groupName, Boolean transactional, InstrumentationManager instrumentationManager, - ExtendedProducerProperties producerProperties, - MessageConverterConfigurer.PartitioningInterceptor partitioningInterceptor) { + ExtendedProducerProperties producerProperties) { this.rocketMQTemplate = rocketMQTemplate; this.destination = destination; this.groupName = groupName; this.transactional = transactional; this.instrumentationManager = instrumentationManager; this.producerProperties = producerProperties; - this.partitioningInterceptor = partitioningInterceptor; } @Override @@ -126,8 +121,6 @@ public class RocketMQMessageHandler extends AbstractMessageHandler implements Li destination, producerProperties.getPartitionCount(), messageQueues.size())); producerProperties.setPartitionCount(messageQueues.size()); - partitioningInterceptor - .setPartitionCount(producerProperties.getPartitionCount()); } } catch (MQClientException e) { diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-stream-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/integration/RocketMQMessageSource.java b/spring-cloud-alibaba-starters/spring-cloud-starter-stream-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/integration/RocketMQMessageSource.java index dd95864e..dd5498e0 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-stream-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/integration/RocketMQMessageSource.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-stream-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/integration/RocketMQMessageSource.java @@ -40,8 +40,8 @@ import org.springframework.beans.factory.DisposableBean; import org.springframework.cloud.stream.binder.ExtendedConsumerProperties; import org.springframework.context.Lifecycle; import org.springframework.integration.IntegrationMessageHeaderAccessor; -import org.springframework.integration.acks.AcknowledgmentCallback; -import org.springframework.integration.acks.AcknowledgmentCallbackFactory; +import org.springframework.integration.support.AcknowledgmentCallback; +import org.springframework.integration.support.AcknowledgmentCallbackFactory; import org.springframework.integration.endpoint.AbstractMessageSource; import org.springframework.integration.support.MessageBuilder; import org.springframework.messaging.Message; @@ -237,6 +237,11 @@ public class RocketMQMessageSource extends AbstractMessageSource } } + @Override + public void destroy() throws Exception { + + } + public static class RocketMQCallbackFactory implements AcknowledgmentCallbackFactory { diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-stream-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/properties/RocketMQBindingProperties.java b/spring-cloud-alibaba-starters/spring-cloud-starter-stream-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/properties/RocketMQBindingProperties.java index 814ae101..439a61d4 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-stream-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/properties/RocketMQBindingProperties.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-stream-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/properties/RocketMQBindingProperties.java @@ -16,19 +16,16 @@ package com.alibaba.cloud.stream.binder.rocketmq.properties; -import org.springframework.cloud.stream.binder.BinderSpecificPropertiesProvider; - /** * @author Timur Valiev * @author Jim */ -public class RocketMQBindingProperties implements BinderSpecificPropertiesProvider { +public class RocketMQBindingProperties { private RocketMQConsumerProperties consumer = new RocketMQConsumerProperties(); private RocketMQProducerProperties producer = new RocketMQProducerProperties(); - @Override public RocketMQConsumerProperties getConsumer() { return consumer; } @@ -37,7 +34,6 @@ public class RocketMQBindingProperties implements BinderSpecificPropertiesProvid this.consumer = consumer; } - @Override public RocketMQProducerProperties getProducer() { return producer; } diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-stream-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/properties/RocketMQExtendedBindingProperties.java b/spring-cloud-alibaba-starters/spring-cloud-starter-stream-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/properties/RocketMQExtendedBindingProperties.java index 890d2250..16a3f76f 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-stream-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/properties/RocketMQExtendedBindingProperties.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-stream-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/properties/RocketMQExtendedBindingProperties.java @@ -1,11 +1,11 @@ /* - * Copyright 2013-2018 the original author or authors. + * Copyright (C) 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 + * http://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, @@ -16,28 +16,71 @@ package com.alibaba.cloud.stream.binder.rocketmq.properties; +import java.util.HashMap; +import java.util.Map; + import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.cloud.stream.binder.AbstractExtendedBindingProperties; -import org.springframework.cloud.stream.binder.BinderSpecificPropertiesProvider; +import org.springframework.cloud.stream.binder.ExtendedBindingProperties; /** * @author Timur Valiev * @author Jim */ @ConfigurationProperties("spring.cloud.stream.rocketmq") -public class RocketMQExtendedBindingProperties extends - AbstractExtendedBindingProperties { +public class RocketMQExtendedBindingProperties implements + ExtendedBindingProperties { - private static final String DEFAULTS_PREFIX = "spring.cloud.stream.rocketmq.default"; + private Map bindings = new HashMap<>(); - @Override - public String getDefaultsPrefix() { - return DEFAULTS_PREFIX; + public Map getBindings() { + return this.bindings; + } + + public void setBindings(Map bindings) { + this.bindings = bindings; } @Override - public Class getExtendedPropertiesEntryClass() { - return RocketMQBindingProperties.class; + public synchronized RocketMQConsumerProperties getExtendedConsumerProperties( + String channelName) { + if (bindings.containsKey(channelName)) { + if (bindings.get(channelName).getConsumer() != null) { + return bindings.get(channelName).getConsumer(); + } + else { + RocketMQConsumerProperties properties = new RocketMQConsumerProperties(); + this.bindings.get(channelName).setConsumer(properties); + return properties; + } + } + else { + RocketMQConsumerProperties properties = new RocketMQConsumerProperties(); + RocketMQBindingProperties rbp = new RocketMQBindingProperties(); + rbp.setConsumer(properties); + bindings.put(channelName, rbp); + return properties; + } } + @Override + public synchronized RocketMQProducerProperties getExtendedProducerProperties( + String channelName) { + if (bindings.containsKey(channelName)) { + if (bindings.get(channelName).getProducer() != null) { + return bindings.get(channelName).getProducer(); + } + else { + RocketMQProducerProperties properties = new RocketMQProducerProperties(); + this.bindings.get(channelName).setProducer(properties); + return properties; + } + } + else { + RocketMQProducerProperties properties = new RocketMQProducerProperties(); + RocketMQBindingProperties rbp = new RocketMQBindingProperties(); + rbp.setProducer(properties); + bindings.put(channelName, rbp); + return properties; + } + } } diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-stream-rocketmq/src/test/java/com/alibaba/cloud/stream/binder/rocketmq/RocketMQAutoConfigurationTests.java b/spring-cloud-alibaba-starters/spring-cloud-starter-stream-rocketmq/src/test/java/com/alibaba/cloud/stream/binder/rocketmq/RocketMQAutoConfigurationTests.java index 5930f0b9..6383e260 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-stream-rocketmq/src/test/java/com/alibaba/cloud/stream/binder/rocketmq/RocketMQAutoConfigurationTests.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-stream-rocketmq/src/test/java/com/alibaba/cloud/stream/binder/rocketmq/RocketMQAutoConfigurationTests.java @@ -16,6 +16,8 @@ package com.alibaba.cloud.stream.binder.rocketmq; +import java.util.Arrays; + import com.alibaba.cloud.stream.binder.rocketmq.config.RocketMQBinderAutoConfiguration; import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQBinderConfigurationProperties; import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQExtendedBindingProperties; @@ -56,7 +58,7 @@ public class RocketMQAutoConfigurationTests { RocketMQBinderConfigurationProperties binderConfigurationProperties = context .getBean(RocketMQBinderConfigurationProperties.class); assertThat(binderConfigurationProperties.getNameServer()) - .isEqualTo("127.0.0.1:9876"); + .isEqualTo(Arrays.asList("127.0.0.1:9876")); RocketMQExtendedBindingProperties bindingProperties = context .getBean(RocketMQExtendedBindingProperties.class); assertThat(