diff --git a/README-zh.md b/README-zh.md index 2e98154d..d6972625 100644 --- a/README-zh.md +++ b/README-zh.md @@ -1,6 +1,6 @@ # Spring Cloud Alibaba -[![CircleCI](https://circleci.com/gh/spring-cloud-incubator/spring-cloud-alibaba/tree/master.svg?style=svg)](https://circleci.com/gh/spring-cloud-incubator/spring-cloud-alibaba/tree/master) +[![CircleCI](https://circleci.com/gh/alibaba/spring-cloud-alibaba/tree/master.svg?style=svg)](https://circleci.com/gh/alibaba/spring-cloud-alibaba/tree/master) [![Maven Central](https://img.shields.io/maven-central/v/org.springframework.cloud/spring-cloud-alibaba-dependencies.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:org.springframework.cloud%20AND%20a:spring-cloud-alibaba-dependencies) [![Codecov](https://codecov.io/gh/spring-cloud-incubator/spring-cloud-alibaba/branch/master/graph/badge.svg)](https://codecov.io/gh/spring-cloud-incubator/spring-cloud-alibaba) [![License](https://img.shields.io/badge/license-Apache%202-4EB1BA.svg)](https://www.apache.org/licenses/LICENSE-2.0.html) diff --git a/README.md b/README.md index 5be375bc..d1e19126 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Spring Cloud Alibaba -[![CircleCI](https://circleci.com/gh/spring-cloud-incubator/spring-cloud-alibaba/tree/master.svg?style=svg)](https://circleci.com/gh/spring-cloud-incubator/spring-cloud-alibaba/tree/master) +[![CircleCI](https://circleci.com/gh/alibaba/spring-cloud-alibaba/tree/master.svg?style=svg)](https://circleci.com/gh/alibaba/spring-cloud-alibaba/tree/master) [![Maven Central](https://img.shields.io/maven-central/v/org.springframework.cloud/spring-cloud-alibaba-dependencies.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:org.springframework.cloud%20AND%20a:spring-cloud-alibaba-dependencies) [![Codecov](https://codecov.io/gh/spring-cloud-incubator/spring-cloud-alibaba/branch/master/graph/badge.svg)](https://codecov.io/gh/spring-cloud-incubator/spring-cloud-alibaba) [![License](https://img.shields.io/badge/license-Apache%202-4EB1BA.svg)](https://www.apache.org/licenses/LICENSE-2.0.html) diff --git a/spring-cloud-alibaba-dependencies/pom.xml b/spring-cloud-alibaba-dependencies/pom.xml index 694b32bd..f4bdb8ba 100644 --- a/spring-cloud-alibaba-dependencies/pom.xml +++ b/spring-cloud-alibaba-dependencies/pom.xml @@ -19,7 +19,7 @@ 1.6.2 3.1.0 - 0.5.1 + 0.7.1 1.1.1 1.0.9 1.0.1 @@ -193,7 +193,7 @@ io.seata - seata-spring + seata-all ${seata.version} diff --git a/spring-cloud-alibaba-examples/acm-example/acm-local-example/src/main/resources/bootstrap.properties b/spring-cloud-alibaba-examples/acm-example/acm-local-example/src/main/resources/bootstrap.properties index 448a0c7d..beea8fed 100644 --- a/spring-cloud-alibaba-examples/acm-example/acm-local-example/src/main/resources/bootstrap.properties +++ b/spring-cloud-alibaba-examples/acm-example/acm-local-example/src/main/resources/bootstrap.properties @@ -2,4 +2,5 @@ spring.application.group=com.alibaba.acm spring.application.name=acm-local server.port=18089 spring.cloud.alicloud.acm.server-list=127.0.0.1 -spring.cloud.alicloud.acm.server-port=8080 \ No newline at end of file +spring.cloud.alicloud.acm.server-port=8080 +management.security.enabled=false \ No newline at end of file diff --git a/spring-cloud-alibaba-examples/seata-example/account-service/src/main/resources/file.conf b/spring-cloud-alibaba-examples/seata-example/account-service/src/main/resources/file.conf index b49739a1..fd3d304f 100644 --- a/spring-cloud-alibaba-examples/seata-example/account-service/src/main/resources/file.conf +++ b/spring-cloud-alibaba-examples/seata-example/account-service/src/main/resources/file.conf @@ -19,16 +19,12 @@ transport { #auto default pin or 8 worker-thread-size = 8 } -} -store { - # branch session size , if exceeded first try compress lockkey, still exceeded throws exceptions - max-branch-session-size = 16384 - # globe session size , if exceeded throws exceptions - max-global-session-size = 512 - # file buffer size , if exceeded allocate new buffer - file-write-buffer-cache-size = 16384 - # when recover batch read size - session.reload.read_size = 100 + shutdown { + # when destroy server, wait seconds + wait = 3 + } + serialization = "seata" + compressor = "none" } service { #vgroup->rgroup @@ -39,6 +35,9 @@ service { enableDegrade = false #disable disable = false + #unit ms,s,m,h,d represents milliseconds, seconds, minutes, hours, days, default permanent + max.commit.retry.timeout = "-1" + max.rollback.retry.timeout = "-1" } client { async.commit.buffer.limit = 10000 @@ -46,4 +45,18 @@ client { retry.internal = 10 retry.times = 30 } + report.retry.count = 5 +} +transaction { + undo.data.validation = true + undo.log.serialization = "jackson" +} + +## metrics settings +metrics { + enabled = false + registry-type = "compact" + # multi exporters use comma divided + exporter-list = "prometheus" + exporter-prometheus-port = 9898 } \ No newline at end of file diff --git a/spring-cloud-alibaba-examples/seata-example/account-service/src/main/resources/registry.conf b/spring-cloud-alibaba-examples/seata-example/account-service/src/main/resources/registry.conf index 587f8bcb..6dbeb22b 100644 --- a/spring-cloud-alibaba-examples/seata-example/account-service/src/main/resources/registry.conf +++ b/spring-cloud-alibaba-examples/seata-example/account-service/src/main/resources/registry.conf @@ -1,5 +1,5 @@ registry { - # file 、nacos 、eureka、redis、zk、consul + # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa type = "file" nacos { @@ -8,7 +8,7 @@ registry { cluster = "default" } eureka { - serviceUrl = "http://localhost:1001/eureka" + serviceUrl = "http://localhost:8761/eureka" application = "default" weight = "1" } @@ -26,13 +26,26 @@ registry { cluster = "default" serverAddr = "127.0.0.1:8500" } + etcd3 { + cluster = "default" + serverAddr = "http://localhost:2379" + } + sofa { + serverAddr = "127.0.0.1:9603" + application = "default" + region = "DEFAULT_ZONE" + datacenter = "DefaultDataCenter" + cluster = "default" + group = "SEATA_GROUP" + addressWaitTime = "3000" + } file { name = "file.conf" } } config { - # file、nacos 、apollo、zk + # file、nacos 、apollo、zk、consul、etcd3 type = "file" nacos { @@ -40,8 +53,11 @@ config { namespace = "public" cluster = "default" } + consul { + serverAddr = "127.0.0.1:8500" + } apollo { - app.id = "fescar-server" + app.id = "seata-server" apollo.meta = "http://192.168.1.204:8801" } zk { @@ -49,7 +65,10 @@ config { session.timeout = 6000 connect.timeout = 2000 } + etcd3 { + serverAddr = "http://localhost:2379" + } file { name = "file.conf" } -} \ No newline at end of file +} diff --git a/spring-cloud-alibaba-examples/seata-example/business-service/src/main/resources/file.conf b/spring-cloud-alibaba-examples/seata-example/business-service/src/main/resources/file.conf index cb1ab8bb..a766d498 100644 --- a/spring-cloud-alibaba-examples/seata-example/business-service/src/main/resources/file.conf +++ b/spring-cloud-alibaba-examples/seata-example/business-service/src/main/resources/file.conf @@ -19,36 +19,12 @@ transport { #auto default pin or 8 worker-thread-size = 8 } -} -## transaction log store -store { - ## store mode: file、db - mode = "file" - - ## file store - file { - dir = "sessionStore" - - # branch session size , if exceeded first try compress lockkey, still exceeded throws exceptions - max-branch-session-size = 16384 - # globe session size , if exceeded throws exceptions - max-global-session-size = 512 - # file buffer size , if exceeded allocate new buffer - file-write-buffer-cache-size = 16384 - # when recover batch read size - session.reload.read_size = 100 - # async, sync - flush-disk-mode = async + shutdown { + # when destroy server, wait seconds + wait = 3 } - - ## database store - db { - driver_class = "" - url = "" - user = "" - password = "" - } - + serialization = "seata" + compressor = "none" } service { #vgroup->rgroup @@ -59,6 +35,9 @@ service { enableDegrade = false #disable disable = false + #unit ms,s,m,h,d represents milliseconds, seconds, minutes, hours, days, default permanent + max.commit.retry.timeout = "-1" + max.rollback.retry.timeout = "-1" } client { async.commit.buffer.limit = 10000 @@ -66,4 +45,18 @@ client { retry.internal = 10 retry.times = 30 } + report.retry.count = 5 +} +transaction { + undo.data.validation = true + undo.log.serialization = "jackson" +} + +## metrics settings +metrics { + enabled = false + registry-type = "compact" + # multi exporters use comma divided + exporter-list = "prometheus" + exporter-prometheus-port = 9898 } \ No newline at end of file diff --git a/spring-cloud-alibaba-examples/seata-example/business-service/src/main/resources/registry.conf b/spring-cloud-alibaba-examples/seata-example/business-service/src/main/resources/registry.conf index 7d71afaa..6dbeb22b 100644 --- a/spring-cloud-alibaba-examples/seata-example/business-service/src/main/resources/registry.conf +++ b/spring-cloud-alibaba-examples/seata-example/business-service/src/main/resources/registry.conf @@ -8,7 +8,7 @@ registry { cluster = "default" } eureka { - serviceUrl = "http://localhost:1001/eureka" + serviceUrl = "http://localhost:8761/eureka" application = "default" weight = "1" } @@ -45,7 +45,7 @@ registry { } config { - # file、nacos 、apollo、zk + # file、nacos 、apollo、zk、consul、etcd3 type = "file" nacos { @@ -53,6 +53,9 @@ config { namespace = "public" cluster = "default" } + consul { + serverAddr = "127.0.0.1:8500" + } apollo { app.id = "seata-server" apollo.meta = "http://192.168.1.204:8801" @@ -62,7 +65,10 @@ config { session.timeout = 6000 connect.timeout = 2000 } + etcd3 { + serverAddr = "http://localhost:2379" + } file { name = "file.conf" } -} \ No newline at end of file +} diff --git a/spring-cloud-alibaba-examples/seata-example/order-service/src/main/resources/file.conf b/spring-cloud-alibaba-examples/seata-example/order-service/src/main/resources/file.conf index 7213edea..536cc785 100644 --- a/spring-cloud-alibaba-examples/seata-example/order-service/src/main/resources/file.conf +++ b/spring-cloud-alibaba-examples/seata-example/order-service/src/main/resources/file.conf @@ -19,36 +19,12 @@ transport { #auto default pin or 8 worker-thread-size = 8 } -} -## transaction log store -store { - ## store mode: file、db - mode = "file" - - ## file store - file { - dir = "sessionStore" - - # branch session size , if exceeded first try compress lockkey, still exceeded throws exceptions - max-branch-session-size = 16384 - # globe session size , if exceeded throws exceptions - max-global-session-size = 512 - # file buffer size , if exceeded allocate new buffer - file-write-buffer-cache-size = 16384 - # when recover batch read size - session.reload.read_size = 100 - # async, sync - flush-disk-mode = async + shutdown { + # when destroy server, wait seconds + wait = 3 } - - ## database store - db { - driver_class = "" - url = "" - user = "" - password = "" - } - + serialization = "seata" + compressor = "none" } service { #vgroup->rgroup @@ -59,6 +35,9 @@ service { enableDegrade = false #disable disable = false + #unit ms,s,m,h,d represents milliseconds, seconds, minutes, hours, days, default permanent + max.commit.retry.timeout = "-1" + max.rollback.retry.timeout = "-1" } client { async.commit.buffer.limit = 10000 @@ -66,4 +45,18 @@ client { retry.internal = 10 retry.times = 30 } + report.retry.count = 5 +} +transaction { + undo.data.validation = true + undo.log.serialization = "jackson" +} + +## metrics settings +metrics { + enabled = false + registry-type = "compact" + # multi exporters use comma divided + exporter-list = "prometheus" + exporter-prometheus-port = 9898 } \ No newline at end of file diff --git a/spring-cloud-alibaba-examples/seata-example/order-service/src/main/resources/registry.conf b/spring-cloud-alibaba-examples/seata-example/order-service/src/main/resources/registry.conf index 7d71afaa..6dbeb22b 100644 --- a/spring-cloud-alibaba-examples/seata-example/order-service/src/main/resources/registry.conf +++ b/spring-cloud-alibaba-examples/seata-example/order-service/src/main/resources/registry.conf @@ -8,7 +8,7 @@ registry { cluster = "default" } eureka { - serviceUrl = "http://localhost:1001/eureka" + serviceUrl = "http://localhost:8761/eureka" application = "default" weight = "1" } @@ -45,7 +45,7 @@ registry { } config { - # file、nacos 、apollo、zk + # file、nacos 、apollo、zk、consul、etcd3 type = "file" nacos { @@ -53,6 +53,9 @@ config { namespace = "public" cluster = "default" } + consul { + serverAddr = "127.0.0.1:8500" + } apollo { app.id = "seata-server" apollo.meta = "http://192.168.1.204:8801" @@ -62,7 +65,10 @@ config { session.timeout = 6000 connect.timeout = 2000 } + etcd3 { + serverAddr = "http://localhost:2379" + } file { name = "file.conf" } -} \ No newline at end of file +} diff --git a/spring-cloud-alibaba-examples/seata-example/readme-zh.md b/spring-cloud-alibaba-examples/seata-example/readme-zh.md index cd310aa3..f8b012aa 100644 --- a/spring-cloud-alibaba-examples/seata-example/readme-zh.md +++ b/spring-cloud-alibaba-examples/seata-example/readme-zh.md @@ -50,6 +50,7 @@ CREATE TABLE `undo_log` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `branch_id` bigint(20) NOT NULL, `xid` varchar(100) NOT NULL, + `context` varchar(128) NOT NULL, `rollback_info` longblob NOT NULL, `log_status` int(11) NOT NULL, `log_created` datetime NOT NULL, @@ -101,13 +102,13 @@ CREATE TABLE `account_tbl` ( 进入解压之后的 bin 目录,执行如下命令来启动 ```$shell -sh seata-server.sh $LISTEN_PORT $MODE(file or db) +sh seata-server.sh -p $LISTEN_PORT -m $MODE(file or db) ``` 在这个示例中,采用如下命令来启动 Seata Server ```$shell -sh seata-server.sh 8091 file +sh seata-server.sh -p 8091 -m file ``` **注意** 如果你修改了endpoint且注册中心使用默认file类型,那么记得需要在各个示例工程中的 `file.conf` 文件中,修改 grouplist 的值(当registry.conf 中registry.type 或 config.type 为file 时会读取内部的file节点中的文件名,若type不为file将直接从配置类型的对应元数据的注册配置中心读取数据),推荐大家使用 nacos 作为配置注册中心。 diff --git a/spring-cloud-alibaba-examples/seata-example/storage-service/src/main/resources/file.conf b/spring-cloud-alibaba-examples/seata-example/storage-service/src/main/resources/file.conf index 4699d684..90cb0ede 100644 --- a/spring-cloud-alibaba-examples/seata-example/storage-service/src/main/resources/file.conf +++ b/spring-cloud-alibaba-examples/seata-example/storage-service/src/main/resources/file.conf @@ -19,36 +19,12 @@ transport { #auto default pin or 8 worker-thread-size = 8 } -} -## transaction log store -store { - ## store mode: file、db - mode = "file" - - ## file store - file { - dir = "sessionStore" - - # branch session size , if exceeded first try compress lockkey, still exceeded throws exceptions - max-branch-session-size = 16384 - # globe session size , if exceeded throws exceptions - max-global-session-size = 512 - # file buffer size , if exceeded allocate new buffer - file-write-buffer-cache-size = 16384 - # when recover batch read size - session.reload.read_size = 100 - # async, sync - flush-disk-mode = async + shutdown { + # when destroy server, wait seconds + wait = 3 } - - ## database store - db { - driver_class = "" - url = "" - user = "" - password = "" - } - + serialization = "seata" + compressor = "none" } service { #vgroup->rgroup @@ -59,6 +35,9 @@ service { enableDegrade = false #disable disable = false + #unit ms,s,m,h,d represents milliseconds, seconds, minutes, hours, days, default permanent + max.commit.retry.timeout = "-1" + max.rollback.retry.timeout = "-1" } client { async.commit.buffer.limit = 10000 @@ -66,4 +45,18 @@ client { retry.internal = 10 retry.times = 30 } + report.retry.count = 5 +} +transaction { + undo.data.validation = true + undo.log.serialization = "jackson" +} + +## metrics settings +metrics { + enabled = false + registry-type = "compact" + # multi exporters use comma divided + exporter-list = "prometheus" + exporter-prometheus-port = 9898 } \ No newline at end of file diff --git a/spring-cloud-alibaba-examples/seata-example/storage-service/src/main/resources/registry.conf b/spring-cloud-alibaba-examples/seata-example/storage-service/src/main/resources/registry.conf index 7d71afaa..6dbeb22b 100644 --- a/spring-cloud-alibaba-examples/seata-example/storage-service/src/main/resources/registry.conf +++ b/spring-cloud-alibaba-examples/seata-example/storage-service/src/main/resources/registry.conf @@ -8,7 +8,7 @@ registry { cluster = "default" } eureka { - serviceUrl = "http://localhost:1001/eureka" + serviceUrl = "http://localhost:8761/eureka" application = "default" weight = "1" } @@ -45,7 +45,7 @@ registry { } config { - # file、nacos 、apollo、zk + # file、nacos 、apollo、zk、consul、etcd3 type = "file" nacos { @@ -53,6 +53,9 @@ config { namespace = "public" cluster = "default" } + consul { + serverAddr = "127.0.0.1:8500" + } apollo { app.id = "seata-server" apollo.meta = "http://192.168.1.204:8801" @@ -62,7 +65,10 @@ config { session.timeout = 6000 connect.timeout = 2000 } + etcd3 { + serverAddr = "http://localhost:2379" + } file { name = "file.conf" } -} \ No newline at end of file +} diff --git a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosDiscoveryProperties.java b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosDiscoveryProperties.java index 30379591..f6cb2506 100644 --- a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosDiscoveryProperties.java +++ b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosDiscoveryProperties.java @@ -155,6 +155,21 @@ public class NacosDiscoveryProperties { */ private String secretKey; + /** + * Heart beat interval. Time unit: second. + */ + private Integer heartBeatInterval; + + /** + * Heart beat timeout. Time unit: second. + */ + private Integer heartBeatTimeout; + + /** + * Ip delete timeout. Time unit: second. + */ + private Integer ipDeleteTimeout; + @Autowired private InetUtils inetUtils; @@ -339,6 +354,30 @@ public class NacosDiscoveryProperties { this.secretKey = secretKey; } + public Integer getHeartBeatInterval() { + return heartBeatInterval; + } + + public void setHeartBeatInterval(Integer heartBeatInterval) { + this.heartBeatInterval = heartBeatInterval; + } + + public Integer getHeartBeatTimeout() { + return heartBeatTimeout; + } + + public void setHeartBeatTimeout(Integer heartBeatTimeout) { + this.heartBeatTimeout = heartBeatTimeout; + } + + public Integer getIpDeleteTimeout() { + return ipDeleteTimeout; + } + + public void setIpDeleteTimeout(Integer ipDeleteTimeout) { + this.ipDeleteTimeout = ipDeleteTimeout; + } + public String getNamingLoadCacheAtStart() { return namingLoadCacheAtStart; } diff --git a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/registry/NacosRegistration.java b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/registry/NacosRegistration.java index c91c33a3..da078747 100644 --- a/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/registry/NacosRegistration.java +++ b/spring-cloud-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/registry/NacosRegistration.java @@ -31,6 +31,7 @@ import org.springframework.util.StringUtils; import com.alibaba.cloud.nacos.NacosDiscoveryProperties; import com.alibaba.nacos.api.naming.NamingService; +import com.alibaba.nacos.api.naming.PreservedMetadataKeys; /** * @author xiaojing @@ -53,11 +54,10 @@ public class NacosRegistration implements Registration, ServiceInstance { @PostConstruct public void init() { - + Map metadata = nacosDiscoveryProperties.getMetadata(); Environment env = context.getEnvironment(); Integer managementPort = ManagementServerPortUtils.getPort(context); if (null != managementPort) { - Map metadata = nacosDiscoveryProperties.getMetadata(); metadata.put(MANAGEMENT_PORT, managementPort.toString()); String contextPath = env.getProperty("management.context-path"); String address = env.getProperty("management.address"); @@ -68,6 +68,19 @@ public class NacosRegistration implements Registration, ServiceInstance { metadata.put(MANAGEMENT_ADDRESS, address); } } + + if (null != nacosDiscoveryProperties.getHeartBeatInterval()) { + metadata.put(PreservedMetadataKeys.HEART_BEAT_INTERVAL, + nacosDiscoveryProperties.getHeartBeatInterval().toString()); + } + if (null != nacosDiscoveryProperties.getHeartBeatTimeout()) { + metadata.put(PreservedMetadataKeys.HEART_BEAT_TIMEOUT, + nacosDiscoveryProperties.getHeartBeatTimeout().toString()); + } + if (null != nacosDiscoveryProperties.getIpDeleteTimeout()) { + metadata.put(PreservedMetadataKeys.IP_DELETE_TIMEOUT, + nacosDiscoveryProperties.getIpDeleteTimeout().toString()); + } } @Override diff --git a/spring-cloud-alibaba-seata/pom.xml b/spring-cloud-alibaba-seata/pom.xml index 4a26f5ce..42f55065 100644 --- a/spring-cloud-alibaba-seata/pom.xml +++ b/spring-cloud-alibaba-seata/pom.xml @@ -16,7 +16,7 @@ io.seata - seata-spring + seata-all diff --git a/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/feign/SentinelInvocationHandler.java b/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/feign/SentinelInvocationHandler.java index 1dc237b6..53ad6944 100644 --- a/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/feign/SentinelInvocationHandler.java +++ b/spring-cloud-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/feign/SentinelInvocationHandler.java @@ -93,45 +93,51 @@ public class SentinelInvocationHandler implements InvocationHandler { MethodMetadata methodMetadata = SentinelContractHolder.metadataMap .get(hardCodedTarget.type().getName() + Feign.configKey(hardCodedTarget.type(), method)); - // resource default is HttpMethod:protocol://url - String resourceName = methodMetadata.template().method().toUpperCase() + ":" - + hardCodedTarget.url() + methodMetadata.template().url(); - Entry entry = null; - try { - ContextUtil.enter(resourceName); - entry = SphU.entry(resourceName, EntryType.OUT, 1, args); + if (methodMetadata == null) { result = methodHandler.invoke(args); } - catch (Throwable ex) { - // fallback handle - if (!BlockException.isBlockException(ex)) { - Tracer.trace(ex); + else { + // resource default is HttpMethod:protocol://url + String resourceName = methodMetadata.template().method().toUpperCase() + + ":" + hardCodedTarget.url() + methodMetadata.template().url(); + Entry entry = null; + try { + ContextUtil.enter(resourceName); + entry = SphU.entry(resourceName, EntryType.OUT, 1, args); + result = methodHandler.invoke(args); } - if (fallbackFactory != null) { - try { - Object fallbackResult = fallbackMethodMap.get(method) - .invoke(fallbackFactory.create(ex), args); - return fallbackResult; + catch (Throwable ex) { + // fallback handle + if (!BlockException.isBlockException(ex)) { + Tracer.trace(ex); } - catch (IllegalAccessException e) { - // shouldn't happen as method is public due to being an interface - throw new AssertionError(e); + if (fallbackFactory != null) { + try { + Object fallbackResult = fallbackMethodMap.get(method) + .invoke(fallbackFactory.create(ex), args); + return fallbackResult; + } + catch (IllegalAccessException e) { + // shouldn't happen as method is public due to being an + // interface + throw new AssertionError(e); + } + catch (InvocationTargetException e) { + throw new AssertionError(e.getCause()); + } } - catch (InvocationTargetException e) { - throw new AssertionError(e.getCause()); + else { + // throw exception if fallbackFactory is null + throw ex; } } - else { - // throw exception if fallbackFactory is null - throw ex; + finally { + if (entry != null) { + entry.exit(1, args); + } + ContextUtil.exit(); } } - finally { - if (entry != null) { - entry.exit(1, args); - } - ContextUtil.exit(); - } } else { // other target type using default strategy diff --git a/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/AcmAutoConfiguration.java b/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/AcmAutoConfiguration.java index 4bb29694..ac82882f 100644 --- a/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/AcmAutoConfiguration.java +++ b/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/AcmAutoConfiguration.java @@ -18,6 +18,7 @@ package com.alibaba.alicloud.acm; import org.springframework.beans.BeansException; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.cloud.context.refresh.ContextRefresher; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; @@ -37,6 +38,7 @@ import com.taobao.diamond.client.Diamond; */ @Configuration @ConditionalOnClass({ Diamond.class }) +@ConditionalOnProperty(name = "spring.cloud.alicloud.acm.enabled", matchIfMissing = true) public class AcmAutoConfiguration implements ApplicationContextAware { private ApplicationContext applicationContext; diff --git a/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/bootstrap/AcmPropertySourceLocator.java b/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/bootstrap/AcmPropertySourceLocator.java index 6f59f333..3dae0710 100644 --- a/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/bootstrap/AcmPropertySourceLocator.java +++ b/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/bootstrap/AcmPropertySourceLocator.java @@ -17,6 +17,7 @@ package com.alibaba.alicloud.acm.bootstrap; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.cloud.bootstrap.config.PropertySourceLocator; import org.springframework.core.env.CompositePropertySource; import org.springframework.core.env.Environment; @@ -28,6 +29,7 @@ import com.alibaba.alicloud.context.acm.AcmIntegrationProperties; * @author juven.xuxb * @author xiaolongzuo */ +@ConditionalOnProperty(name = "spring.cloud.alicloud.acm.enabled", matchIfMissing = true) public class AcmPropertySourceLocator implements PropertySourceLocator { private static final String DIAMOND_PROPERTY_SOURCE_NAME = "diamond"; diff --git a/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/endpoint/AcmEndpointAutoConfiguration.java b/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/endpoint/AcmEndpointAutoConfiguration.java index 9fa10922..b57c38c6 100644 --- a/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/endpoint/AcmEndpointAutoConfiguration.java +++ b/spring-cloud-alicloud-acm/src/main/java/com/alibaba/alicloud/acm/endpoint/AcmEndpointAutoConfiguration.java @@ -19,6 +19,7 @@ package com.alibaba.alicloud.acm.endpoint; 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.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.context.annotation.Bean; @@ -31,6 +32,7 @@ import com.alibaba.alicloud.context.acm.AcmProperties; */ @ConditionalOnWebApplication @ConditionalOnClass(name = "org.springframework.boot.actuate.endpoint.AbstractEndpoint") +@ConditionalOnProperty(name = "spring.cloud.alicloud.acm.enabled", matchIfMissing = true) public class AcmEndpointAutoConfiguration { @Autowired diff --git a/spring-cloud-alicloud-acm/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-cloud-alicloud-acm/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 29f53c76..34d3e4f9 100644 --- a/spring-cloud-alicloud-acm/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/spring-cloud-alicloud-acm/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -4,6 +4,12 @@ "name": "spring.application.group", "type": "java.lang.String", "description": "spring application group." + }, + { + "name": "spring.cloud.alicloud.acm.enabled", + "type": "java.lang.Boolean", + "defaultValue": true, + "description": "enable acm or not." } ] } \ No newline at end of file