diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 00000000..7146573a --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,29 @@ +## Contributor Code of Conduct + +As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities. + +We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality. + +Examples of unacceptable behavior by participants include: + +- The use of sexualized language or imagery + +- Personal attacks + +- Trolling or insulting/derogatory comments + +- Public or private harassment + +- Publishing other’s private information, such as physical or electronic addresses, without explicit permission + +- Other unethical or unprofessional conduct + +Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. + +By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team. + +This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. + +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting a project maintainer at spring-code-of-conduct@pivotal.io . All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. Maintainers are obligated to maintain confidentiality with regard to the reporter of an incident. + +This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org/), version 1.3.0, available at [contributor-covenant.org/version/1/3/0/](http://contributor-covenant.org/version/1/3/0/) diff --git a/README-zh.md b/README-zh.md index f308f309..65a939b5 100644 --- a/README-zh.md +++ b/README-zh.md @@ -1,10 +1,17 @@ # 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) +[![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) + Spring Cloud Alibaba 致力于提供微服务开发的一站式解决方案。此项目包含开发分布式应用微服务的必需组件,方便开发者通过 Spring Cloud 编程模型轻松使用这些组件来开发分布式应用服务。 依托 Spring Cloud Alibaba,您只需要添加一些注解和少量配置,就可以将 Spring Cloud 应用接入阿里微服务解决方案,通过阿里中间件来迅速搭建分布式应用系统。 -参考文档 请查看 [WIKI](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/wiki) +参考文档 请查看 [WIKI](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/wiki) 。 + +为 Spring Cloud Alibaba 贡献代码请参考 [如何贡献](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/wiki/%E5%A6%82%E4%BD%95%E8%B4%A1%E7%8C%AE%E4%BB%A3%E7%A0%81) 。 ## 主要功能 @@ -12,8 +19,10 @@ Spring Cloud Alibaba 致力于提供微服务开发的一站式解决方案。 * **服务注册与发现**:适配 Spring Cloud 服务注册与发现标准,默认集成了 Ribbon 的支持。 * **分布式配置管理**:支持分布式系统中的外部化配置,配置更改时自动刷新。 * **消息驱动能力**:基于 Spring Cloud Stream 为微服务应用构建消息驱动能力。 +* **分布式事务**:使用 @GlobalTransactional 注解, 高效并且对业务零侵入地解决分布式事务问题。。 * **阿里云对象存储**:阿里云提供的海量、安全、低成本、高可靠的云存储服务。支持在任何应用、任何时间、任何地点存储和访问任意类型的数据。 * **分布式任务调度**:提供秒级、精准、高可靠、高可用的定时(基于 Cron 表达式)任务调度服务。同时提供分布式的任务执行模型,如网格任务。网格任务支持海量子任务均匀分配到所有 Worker(schedulerx-client)上执行。 +* **阿里云短信服务**:覆盖全球的短信服务,友好、高效、智能的互联化通讯能力,帮助企业迅速搭建客户触达通道。 更多功能请参考 [Roadmap](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/Roadmap-zh.md)。 @@ -26,11 +35,17 @@ Spring Cloud Alibaba 致力于提供微服务开发的一站式解决方案。 **[RocketMQ](https://rocketmq.apache.org/)**:一款开源的分布式消息系统,基于高可用分布式集群技术,提供低延时的、高可靠的消息发布与订阅服务。 +**[Dubbo](https://github.com/apache/incubator-dubbo)**:Apache Dubbo™ (incubating) 是一款高性能 Java RPC 框架。 + +**[Fescar](https://github.com/alibaba/fescar)**:阿里巴巴开源产品,一个易于使用的高性能微服务分布式事务解决方案。 + **[Alibaba Cloud ACM](https://www.aliyun.com/product/acm)**:一款在分布式架构环境中对应用配置进行集中管理和推送的应用配置中心产品。 **[Alibaba Cloud OSS](https://www.aliyun.com/product/oss)**: 阿里云对象存储服务(Object Storage Service,简称 OSS),是阿里云提供的海量、安全、低成本、高可靠的云存储服务。您可以在任何应用、任何时间、任何地点存储和访问任意类型的数据。 -**[Alibaba Cloud SchedulerX](https://help.aliyun.com/document_detail/43136.html?spm=a2c4g.11186623.6.709.baef7da9QVICiD)**: 阿里中间件团队开发的一款分布式任务调度产品,提供秒级、精准、高可靠、高可用的定时(基于 Cron 表达式)任务调度服务。 +**[Alibaba Cloud SchedulerX](https://help.aliyun.com/document_detail/43136.html)**: 阿里中间件团队开发的一款分布式任务调度产品,提供秒级、精准、高可靠、高可用的定时(基于 Cron 表达式)任务调度服务。 + +**[Alibaba Cloud SMS](https://www.aliyun.com/product/sms)**: 覆盖全球的短信服务,友好、高效、智能的互联化通讯能力,帮助企业迅速搭建客户触达通道。 更多组件请参考 [Roadmap](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/Roadmap-zh.md)。 @@ -48,7 +63,7 @@ Spring Cloud 使用 Maven 来构建,最快的使用方式是将本项目clone ## 如何使用 ### 如何引入依赖 -项目已经发布了第一个版本,版本 0.2.0.RELEASE 对应的是 Spring Cloud Finchley 版本,版本 0.1.0.RELEASE 对应的是 Spring Cloud Edgware 版本。 +项目的最新版本是 0.2.1.RELEASE 和 0.1.1.RELEASE,版本 0.2.1.RELEASE 对应的是 Spring Cloud Finchley 版本,版本 0.1.1.RELEASE 对应的是 Spring Cloud Edgware 版本。 如果需要使用已发布的版本,在 `dependencyManagement` 中添加如下配置。 @@ -57,14 +72,14 @@ Spring Cloud 使用 Maven 来构建,最快的使用方式是将本项目clone org.springframework.cloud spring-cloud-alibaba-dependencies - 0.2.0.RELEASE + 0.2.1.RELEASE pom import -然后再 `dependencies` 中添加自己所需使用的依赖即可使用。 +然后在 `dependencies` 中添加自己所需使用的依赖即可使用。 如果您想体验最新的 BUILD-SNAPSHOT 的新功能,则可以将版本换成最新的版本,但是需要在 pom.xml 中配置 Spring BUILDSNAPSHOT 仓库,**注意: SNAPSHOT 版本随时可能更新** @@ -93,6 +108,8 @@ Example 列表: [RocketMQ Example](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-examples/rocketmq-example/readme-zh.md) +[Fescar Example](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-examples/fescar-example/readme-zh.md) + [Alibaba Cloud OSS Example](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-examples/oss-example/readme-zh.md) [Alibaba Cloud ANS Example](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-examples/ans-example/ans-provider-example/readme-zh.md) @@ -102,7 +119,7 @@ Example 列表: [Alibaba Cloud SchedulerX Example](https://github.com/xiaolongzuo/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-examples/schedulerx-example/schedulerx-simple-task-example/readme-zh.md) ## 版本管理规范 -项目的版本号格式为 x.x.x 的形式,其中 x 的数值类型为数字,从0开始取值,且不限于 0~9 这个范围。项目处于孵化器阶段时,第一位版本号固定使用0,即版本号为 0.x.x 的格式。 +项目的版本号格式为 x.x.x 的形式,其中 x 的数值类型为数字,从 0 开始取值,且不限于 0~9 这个范围。项目处于孵化器阶段时,第一位版本号固定使用 0,即版本号为 0.x.x 的格式。 由于 Spring Boot 1 和 Spring Boot 2 在 Actuator 模块的接口和注解有很大的变更,且 spring-cloud-commons 从 1.x.x 版本升级到 2.0.0 版本也有较大的变更,因此我们使用了两个不同分支来分别支持 Spring Boot 1 和 Spring Boot 2: * 0.1.x 版本适用于 Spring Boot 1 diff --git a/README.md b/README.md index a4e58ab8..54e6194f 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,10 @@ # 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) +[![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) + A project maintained by Alibaba. See the [中文文档](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/README-zh.md) for Chinese readme. @@ -15,21 +20,33 @@ With Spring Cloud Alibaba, you only need to add some annotations and a small amo * **Service registration and discovery**:Service can be registered and clients can discover the instances using Spring-managed beans, auto integration Ribbon. * **Distributed configuration**:support for externalized configuration in a distributed system, auto refresh when configuration changes. * **Event-driven**:support for building highly scalable event-driven microservices connected with shared messaging systems. +* **Distributed Transaction**:support for distributed transaction solution with high performance and ease of use. * **Alibaba Cloud Object Storage**:massive, secure, low-cost, and highly reliable cloud storage services. Support for storing and accessing any type of data in any application, anytime, anywhere. +* **Alibaba Cloud SchedulerX**:accurate, highly reliable, and highly available scheduled job scheduling services with response time within seconds. +* **Alibaba Cloud SMS**: A messaging service that covers the globe, Alibaba SMS provides convenient, efficient, and intelligent communication capabilities that help businesses quickly contact their customers. + For more features, please refer to [Roadmap](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/Roadmap.md). ## Components **[Sentinel](https://github.com/alibaba/Sentinel)**: Sentinel takes "traffic flow" as the breakthrough point, and provides solutions in areas such as flow control, concurrency, circuit breaking, and load protection to protect service stability. -**[Nacos](https://github.com/alibaba/Nacos)**: an easy-to-use dynamic service discovery, configuration and service management platform for building cloud native applications. +**[Nacos](https://github.com/alibaba/Nacos)**: An easy-to-use dynamic service discovery, configuration and service management platform for building cloud native applications. -**[RocketMQ](https://rocketmq.apache.org/)**:a distributed messaging and streaming platform with low latency, high performance and reliability, trillion-level capacity and flexible scalability. +**[RocketMQ](https://rocketmq.apache.org/)**:A distributed messaging and streaming platform with low latency, high performance and reliability, trillion-level capacity and flexible scalability. -**[Alibaba Cloud ACM](https://www.aliyun.com/product/acm)**:an application configuration center that enables you to centralize the management of application configurations, and accomplish real-time configuration push in a distributed environment. +**[Dubbo](https://github.com/apache/incubator-dubbo)**:A high-performance, Java based open source RPC framework. + +**[Fescar](https://github.com/alibaba/fescar)**:A distributed transaction solution with high performance and ease of use for microservices architecture. + +**[Alibaba Cloud ACM](https://www.aliyun.com/product/acm)**:An application configuration center that enables you to centralize the management of application configurations, and accomplish real-time configuration push in a distributed environment. **[Alibaba Cloud OSS](https://www.aliyun.com/product/oss)**: An encrypted and secure cloud storage service which stores, processes and accesses massive amounts of data from anywhere in the world. +**[Alibaba Cloud SMS](https://www.aliyun.com/product/sms)**: A messaging service that covers the globe, Alibaba SMS provides convenient, efficient, and intelligent communication capabilities that help businesses quickly contact their customers. + +**[Alibaba Cloud SchedulerX](https://www.aliyun.com/product/SchedulerX)**:accurate, highly reliable, and highly available scheduled job scheduling services with response time within seconds.. + For more features please refer to [Roadmap](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/Roadmap.md). ## How to build @@ -45,7 +62,7 @@ Spring Cloud uses Maven for most build-related activities, and you should be abl ## How to Use ### Add maven dependency -Version 0.2.0.RELEASE is compatible with the Spring Cloud Finchley. Version 0.1.0.RELEASE is compatible with the Spring Cloud Edgware. +Version 0.2.1.RELEASE is compatible with the Spring Cloud Finchley. Version 0.1.1.RELEASE is compatible with the Spring Cloud Edgware. These artifacts are available from Maven Central and Spring Release repository via BOM: @@ -54,7 +71,7 @@ These artifacts are available from Maven Central and Spring Release repository v org.springframework.cloud spring-cloud-alibaba-dependencies - 0.2.0.RELEASE + 0.2.1.RELEASE pom import @@ -115,6 +132,28 @@ During the incubation period, the version management of the project will follow * Functional updates will be reflected in the 3rd number of the version, for example, the next version of 0.1.0 will be 0.1.1. +## Code of Conduct +This project is a sub-project of Spring Cloud, it adheres to the Contributor Covenant [code of conduct](https://github.com/spring-cloud/spring-cloud-build/blob/master/docs/src/main/asciidoc/code-of-conduct.adoc). By participating, you are expected to uphold this code. Please report unacceptable behavior to spring-code-of-conduct@pivotal.io. + +## Code Conventions and Housekeeping +None of these is essential for a pull request, but they will all help. They can also be added after the original pull request but before a merge. + +Use the Spring Framework code format conventions. If you use Eclipse you can import formatter settings using the eclipse-code-formatter.xml file from the Spring Cloud Build project. If using IntelliJ, you can use the Eclipse Code Formatter Plugin to import the same file. + +Make sure all new .java files to have a simple Javadoc class comment with at least an @author tag identifying you, and preferably at least a paragraph on what the class is for. + +Add the ASF license header comment to all new .java files (copy from existing files in the project) + +Add yourself as an @author to the .java files that you modify substantially (more than cosmetic changes). + +Add some Javadocs and, if you change the namespace, some XSD doc elements. + +A few unit tests would help a lot as well — someone has to do it. + +If no-one else is using your branch, please rebase it against the current master (or other target branch in the main project). + +When writing a commit message please follow these conventions, if you are fixing an existing issue please add Fixes gh-XXXX at the end of the commit message (where XXXX is the issue number). + ## Contact Us Mailing list is recommended for discussing almost anything related to spring-cloud-alibaba. diff --git a/Roadmap-zh.md b/Roadmap-zh.md index c28fe972..8bf69a79 100644 --- a/Roadmap-zh.md +++ b/Roadmap-zh.md @@ -4,29 +4,39 @@ Spring Cloud Alibaba 致力于提供分布式应用服务开发的一站式解 此项目包含的组件内容,主要选取自阿里巴巴开源中间件和阿里云商业化产品,但也不限定于这些产品。 -如果您对 Roadmap 有任何建议或想法,欢迎在 issue 中或者通过其他社区渠道向我们提出,一起讨论。 +如果您对 Roadmap 有任何建议或想法,欢迎在 issues 中或者通过其他社区渠道向我们提出,一起讨论。 ## 已包含的组件 **Sentinel** -阿里巴巴开源产品,把流量作为切入点,从流量控制,熔断降级,系统负载保护等多个维度保护服务的稳定性。 + +阿里巴巴开源产品,把流量作为切入点,从流量控制、熔断降级、系统负载保护等多个维度保护服务的稳定性。 **Nacos** + 阿里巴巴开源产品,一个更易于构建云原生应用的动态服务发现、配置管理和服务管理平台。 +**RocketMQ** + +Apache RocketMQ™ 基于 Java 的高性能、高吞吐量的分布式消息和流计算平台。 + +**Dubbo** + +Apache Dubbo™ (incubating) 是一款高性能 Java RPC 框架。 + +**Fescar** + +阿里巴巴开源产品,一个易于使用的高性能微服务分布式事务解决方案。 + **Alibaba Cloud OSS** + 阿里云对象存储服务(Object Storage Service,简称 OSS),是阿里云提供的海量、安全、低成本、高可靠的云存储服务。您可以在任何应用、任何时间、任何地点存储和访问任意类型的数据。 -## 即将加入的组件 -**Dubbo** -Apache Dubbo™ (incubating) 是一款高性能Java RPC框架。 +**Alibaba Cloud SchedulerX** -**RocketMQ** -Apache RocketMQ™ 基于Java的高性能、高吞吐量的分布式消息和流计算平台。 - -**Alibaba Cloud Schedulerx** 阿里中间件团队开发的一款分布式任务调度产品,支持周期性的任务与固定时间点触发任务。 -**Alibaba Cloud SLS** -针对日志类数据的一站式服务,在阿里巴巴集团经历大量大数据场景锤炼而成。您无需开发就能快捷完成日志数据采集、消费、投递以及查询分析等功能,提升运维、运营效率,建立 DT 时代海量日志处理能力。 \ No newline at end of file +**Alibaba Cloud SMS** + +覆盖全球的短信服务,友好、高效、智能的互联化通讯能力,帮助企业迅速搭建客户触达通道。 diff --git a/Roadmap.md b/Roadmap.md index 7b392f2a..e7b99498 100644 --- a/Roadmap.md +++ b/Roadmap.md @@ -20,20 +20,27 @@ An open-source project of Alibaba, Sentinel takes "flow" as breakthrough point, An opensource project of Alibaba, an easy-to-use dynamic service discovery, configuration and service management platform for building cloud native applications. +**RocketMQ** + +Apache RocketMQ™ is an open source distributed messaging and streaming data platform. + +**Dubbo** + +Apache Dubbo™ (incubating) is a high-performance, Java based open source RPC framework. + +**Fescar** + +A distributed transaction solution with high performance and ease of use for microservices architecture. + **Alibaba Cloud OSS** Alibaba Cloud Object Storage Service, An encrypted and secure cloud storage service which stores, processes and accesses massive amounts of data from anywhere in the world. -More components will be supported by Spring Cloud Alibaba in the future, which may include but are not limited to the following: - -**Dubbo** -Apache Dubbo™ (incubating) is a high-performance, Java based open source RPC framework. - -**RocketMQ** -Apache RocketMQ™ is an open source distributed messaging and streaming data platform. - **Alibaba Cloud Schedulerx** + A distributed task scheduling product developed by Alibaba Middleware team. It supports both periodical tasks and tasks to be triggered at specified time points. -**Alibaba Cloud SLS** -Aliyun Log Service is an all-in-one service for log-type data. It helps increase Operations & Management and operational efficiency, as well as build the processing capability to deal with massive logs. \ No newline at end of file +**Alibaba Cloud SMS** + +A messaging service that covers the globe, Alibaba SMS provides convenient, efficient, and intelligent communication capabilities that help businesses quickly contact their customers. + diff --git a/pom.xml b/pom.xml index edfd5e55..15b89329 100644 --- a/pom.xml +++ b/pom.xml @@ -88,6 +88,7 @@ spring-cloud-alibaba-sentinel-datasource spring-cloud-alibaba-nacos-config spring-cloud-alibaba-nacos-discovery + spring-cloud-alibaba-fescar spring-cloud-stream-binder-rocketmq spring-cloud-alibaba-examples spring-cloud-alibaba-test diff --git a/spring-cloud-alibaba-dependencies/pom.xml b/spring-cloud-alibaba-dependencies/pom.xml index 6c5c3025..79cb30f8 100644 --- a/spring-cloud-alibaba-dependencies/pom.xml +++ b/spring-cloud-alibaba-dependencies/pom.xml @@ -19,6 +19,7 @@ 1.4.0 3.1.0 0.6.2 + 0.1.3 1.0.8 1.0.1 4.0.1 @@ -70,11 +71,34 @@ schedulerX-client ${schedulerX.client.version} + + + + com.aliyun.mns + aliyun-sdk-mns + ${aliyun.sdk.mns} + + + + com.aliyun + aliyun-java-sdk-dysmsapi + ${aliyun.java.sdk.dysmsapi} + + com.alibaba.nacos nacos-client ${nacos.version} + + + + org.apache.rocketmq + rocketmq-client + ${rocketmq.version} + + + com.alibaba.csp sentinel-core @@ -141,13 +165,28 @@ ${sentinel.version} + - org.apache.rocketmq - rocketmq-client - ${rocketmq.version} + com.alibaba.fescar + fescar-core + ${fescar.version} + + + com.alibaba.fescar + fescar-common + ${fescar.version} + + + com.alibaba.fescar + fescar-spring + ${fescar.version} + + + com.alibaba.fescar + fescar-rm-datasource + ${fescar.version} - @@ -156,19 +195,6 @@ ${oss.version} - - - com.aliyun.mns - aliyun-sdk-mns - ${aliyun.sdk.mns} - - - - com.aliyun - aliyun-java-sdk-dysmsapi - ${aliyun.java.sdk.dysmsapi} - - org.springframework.cloud @@ -195,6 +221,11 @@ spring-cloud-alibaba-nacos-config ${project.version} + + org.springframework.cloud + spring-cloud-alibaba-fescar + ${project.version} + org.springframework.cloud spring-cloud-alicloud-acm @@ -238,6 +269,12 @@ ${project.version} + + org.springframework.cloud + spring-cloud-starter-alibaba-fescar + ${project.version} + + org.springframework.cloud spring-cloud-starter-alibaba-nacos-discovery @@ -268,12 +305,6 @@ ${project.version} - - org.springframework.cloud - spring-cloud-starter-alicloud-sms - ${project.version} - - org.springframework.cloud spring-cloud-starter-stream-rocketmq @@ -286,6 +317,13 @@ ${project.version} + + + org.springframework.cloud + spring-cloud-starter-alicloud-sms + ${project.version} + + diff --git a/spring-cloud-alibaba-examples/fescar-example/account-service/pom.xml b/spring-cloud-alibaba-examples/fescar-example/account-service/pom.xml new file mode 100644 index 00000000..ce03c1c8 --- /dev/null +++ b/spring-cloud-alibaba-examples/fescar-example/account-service/pom.xml @@ -0,0 +1,63 @@ + + + + spring-cloud-alibaba-examples + org.springframework.cloud + 0.1.2.BUILD-SNAPSHOT + ../../pom.xml + + 4.0.0 + account-service + + + + org.springframework.cloud + spring-cloud-starter-alibaba-fescar + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.boot + spring-boot-starter-jdbc + + + + mysql + mysql-connector-java + + + + + + + + org.codehaus.mojo + cobertura-maven-plugin + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + org.codehaus.mojo + cobertura-maven-plugin + false + + true + + + + + + \ No newline at end of file diff --git a/spring-cloud-alibaba-examples/fescar-example/account-service/src/main/java/org/springframework/cloud/alibaba/cloud/examples/AccountApplication.java b/spring-cloud-alibaba-examples/fescar-example/account-service/src/main/java/org/springframework/cloud/alibaba/cloud/examples/AccountApplication.java new file mode 100644 index 00000000..893d3464 --- /dev/null +++ b/spring-cloud-alibaba-examples/fescar-example/account-service/src/main/java/org/springframework/cloud/alibaba/cloud/examples/AccountApplication.java @@ -0,0 +1,32 @@ +/* + * Copyright (C) 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 + * + * 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, + * 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 org.springframework.cloud.alibaba.cloud.examples; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * @author xiaojing + */ +@SpringBootApplication +public class AccountApplication { + + public static void main(String[] args) { + SpringApplication.run(AccountApplication.class, args); + } + +} diff --git a/spring-cloud-alibaba-examples/fescar-example/account-service/src/main/java/org/springframework/cloud/alibaba/cloud/examples/AccountController.java b/spring-cloud-alibaba-examples/fescar-example/account-service/src/main/java/org/springframework/cloud/alibaba/cloud/examples/AccountController.java new file mode 100644 index 00000000..3738fb87 --- /dev/null +++ b/spring-cloud-alibaba-examples/fescar-example/account-service/src/main/java/org/springframework/cloud/alibaba/cloud/examples/AccountController.java @@ -0,0 +1,66 @@ +/* + * Copyright (C) 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 + * + * 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, + * 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 org.springframework.cloud.alibaba.cloud.examples; + +import java.util.Random; + +import com.alibaba.fescar.core.context.RootContext; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +/** + * @author xiaojing + */ +@RestController +public class AccountController { + + private static final Logger LOGGER = LoggerFactory.getLogger(AccountController.class); + + private static final String SUCCESS = "SUCCESS"; + private static final String FAIL = "FAIL"; + + private final JdbcTemplate jdbcTemplate; + private Random random; + + public AccountController(JdbcTemplate jdbcTemplate) { + this.jdbcTemplate = jdbcTemplate; + this.random = new Random(); + } + + @RequestMapping(value = "/account", method = RequestMethod.POST, produces = "application/json") + public String account(String userId, int money) { + LOGGER.info("Account Service ... xid: " + RootContext.getXID()); + + if (random.nextBoolean()) { + throw new RuntimeException("this is a mock Exception"); + } + + int result = jdbcTemplate.update( + "update account_tbl set money = money - ? where user_id = ?", + new Object[] { money, userId }); + LOGGER.info("Account Service End ... "); + if (result == 1) { + return SUCCESS; + } + return FAIL; + } + +} diff --git a/spring-cloud-alibaba-examples/fescar-example/account-service/src/main/java/org/springframework/cloud/alibaba/cloud/examples/DatabaseConfiguration.java b/spring-cloud-alibaba-examples/fescar-example/account-service/src/main/java/org/springframework/cloud/alibaba/cloud/examples/DatabaseConfiguration.java new file mode 100644 index 00000000..6e6bf184 --- /dev/null +++ b/spring-cloud-alibaba-examples/fescar-example/account-service/src/main/java/org/springframework/cloud/alibaba/cloud/examples/DatabaseConfiguration.java @@ -0,0 +1,93 @@ +/* + * Copyright (C) 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 + * + * 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, + * 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 org.springframework.cloud.alibaba.cloud.examples; + +import java.sql.SQLException; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.core.env.Environment; +import org.springframework.jdbc.core.JdbcTemplate; + +import com.alibaba.druid.pool.DruidDataSource; +import com.alibaba.fescar.rm.datasource.DataSourceProxy; + +/** + * @author xiaojing + */ +@Configuration +public class DatabaseConfiguration { + + private final ApplicationContext applicationContext; + + public DatabaseConfiguration(ApplicationContext applicationContext) { + this.applicationContext = applicationContext; + } + + @Bean(initMethod = "init", destroyMethod = "close") + @Primary + public DruidDataSource druidDataSource() throws SQLException { + + Environment environment = applicationContext.getEnvironment(); + + String ip = environment.getProperty("mysql.server.ip"); + String port = environment.getProperty("mysql.server.port"); + String dbName = environment.getProperty("mysql.db.name"); + + String userName = environment.getProperty("mysql.user.name"); + String password = environment.getProperty("mysql.user.password"); + + DruidDataSource druidDataSource = new DruidDataSource(); + druidDataSource.setUrl("jdbc:mysql://" + ip + ":" + port + "/" + dbName); + druidDataSource.setUsername(userName); + druidDataSource.setPassword(password); + druidDataSource.setDriverClassName("com.mysql.jdbc.Driver"); + druidDataSource.setInitialSize(0); + druidDataSource.setMaxActive(180); + druidDataSource.setMaxWait(60000); + druidDataSource.setMinIdle(0); + druidDataSource.setValidationQuery("Select 'x' from DUAL"); + druidDataSource.setTestOnBorrow(false); + druidDataSource.setTestOnReturn(false); + druidDataSource.setTestWhileIdle(true); + druidDataSource.setTimeBetweenEvictionRunsMillis(60000); + druidDataSource.setMinEvictableIdleTimeMillis(25200000); + druidDataSource.setRemoveAbandoned(true); + druidDataSource.setRemoveAbandonedTimeout(1800); + druidDataSource.setLogAbandoned(true); + druidDataSource.setFilters("mergeStat"); + return druidDataSource; + } + + @Bean + public DataSourceProxy dataSourceProxy(DruidDataSource druidDataSource) { + return new DataSourceProxy(druidDataSource); + } + + @Bean + public JdbcTemplate jdbcTemplate(DataSourceProxy dataSourceProxy) { + JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSourceProxy); + + jdbcTemplate.update("delete from account_tbl where user_id = 'U100001'"); + jdbcTemplate.update( + "insert into account_tbl(user_id, money) values ('U100001', 10000)"); + + return jdbcTemplate; + } + +} diff --git a/spring-cloud-alibaba-examples/fescar-example/account-service/src/main/resources/application.conf b/spring-cloud-alibaba-examples/fescar-example/account-service/src/main/resources/application.conf new file mode 100644 index 00000000..b264dd9d --- /dev/null +++ b/spring-cloud-alibaba-examples/fescar-example/account-service/src/main/resources/application.conf @@ -0,0 +1,30 @@ +transport { + # tcp udt unix-domain-socket + type = "TCP" + #NIO NATIVE + server = "NIO" + #thread factory for netty + thread-factory { + boss-thread-prefix = "NettyBoss" + worker-thread-prefix = "NettyServerNIOWorker" + server-executor-thread-prefix = "NettyServerBizHandler" + share-boss-worker = false + client-selector-thread-prefix = "NettyClientSelector" + client-selector-thread-size = 1 + client-worker-thread-prefix = "NettyClientWorkerThread" + # netty boss thread size,will not be used for UDT + boss-thread-size = 1 + #auto default pin or 8 + worker-thread-size = 8 + } +} +service { + #vgroup->rgroup + vgroup_mapping.account-service-fescar-service-group = "localRgroup" + #only support single node + localRgroup.grouplist = "127.0.0.1:8091" + #degrade current not support + enableDegrade = false + #disable + disable = false +} diff --git a/spring-cloud-alibaba-examples/fescar-example/account-service/src/main/resources/application.properties b/spring-cloud-alibaba-examples/fescar-example/account-service/src/main/resources/application.properties new file mode 100644 index 00000000..10f45c59 --- /dev/null +++ b/spring-cloud-alibaba-examples/fescar-example/account-service/src/main/resources/application.properties @@ -0,0 +1,9 @@ +spring.application.name=account-service +server.port=18084 + +mysql.server.ip=127.0.0.1 +mysql.server.port=3306 +mysql.db.name=demo + +mysql.user.name=xxxxx +mysql.user.password=xxxxx \ No newline at end of file diff --git a/spring-cloud-alibaba-examples/fescar-example/business-service/pom.xml b/spring-cloud-alibaba-examples/fescar-example/business-service/pom.xml new file mode 100644 index 00000000..bcbfeca3 --- /dev/null +++ b/spring-cloud-alibaba-examples/fescar-example/business-service/pom.xml @@ -0,0 +1,62 @@ + + + + spring-cloud-alibaba-examples + org.springframework.cloud + 0.1.2.BUILD-SNAPSHOT + ../../pom.xml + + 4.0.0 + business-service + + + + org.springframework.cloud + spring-cloud-starter-alibaba-fescar + + + org.springframework.cloud + spring-cloud-starter-feign + + + org.springframework.cloud + spring-cloud-starter-netflix-hystrix + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.cloud + spring-cloud-starter-alibaba-sentinel + + + + + + + + org.codehaus.mojo + cobertura-maven-plugin + + + + + + org.codehaus.mojo + cobertura-maven-plugin + false + + true + + + + + + \ No newline at end of file diff --git a/spring-cloud-alibaba-examples/fescar-example/business-service/src/main/java/org/springframework/cloud/alibaba/cloud/examples/BusinessApplication.java b/spring-cloud-alibaba-examples/fescar-example/business-service/src/main/java/org/springframework/cloud/alibaba/cloud/examples/BusinessApplication.java new file mode 100644 index 00000000..82b7496a --- /dev/null +++ b/spring-cloud-alibaba-examples/fescar-example/business-service/src/main/java/org/springframework/cloud/alibaba/cloud/examples/BusinessApplication.java @@ -0,0 +1,63 @@ +/* + * Copyright (C) 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 + * + * 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, + * 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 org.springframework.cloud.alibaba.cloud.examples; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.netflix.feign.EnableFeignClients; +import org.springframework.cloud.netflix.feign.FeignClient; +import org.springframework.context.annotation.Bean; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.client.RestTemplate; + +/** + * @author xiaojing + */ +@SpringBootApplication +@EnableFeignClients +public class BusinessApplication { + + public static void main(String[] args) { + SpringApplication.run(BusinessApplication.class, args); + } + + @Bean + public RestTemplate restTemplate() { + return new RestTemplate(); + } + + @FeignClient(value = "storage", url = "http://127.0.0.1:18082") + public interface StorageService { + + @RequestMapping(path = "/storage/{commodityCode}/{count}") + String storage(@RequestParam("commodityCode") String commodityCode, + @RequestParam("count") int count); + + } + + @FeignClient(value = "order", url = "http://127.0.0.1:18083") + public interface OrderService { + + @RequestMapping(path = "/order", method = RequestMethod.POST) + String order(@RequestParam("userId") String userId, + @RequestParam("commodityCode") String commodityCode, + @RequestParam("orderCount") int orderCount); + + } +} diff --git a/spring-cloud-alibaba-examples/fescar-example/business-service/src/main/java/org/springframework/cloud/alibaba/cloud/examples/HomeController.java b/spring-cloud-alibaba-examples/fescar-example/business-service/src/main/java/org/springframework/cloud/alibaba/cloud/examples/HomeController.java new file mode 100644 index 00000000..039074ec --- /dev/null +++ b/spring-cloud-alibaba-examples/fescar-example/business-service/src/main/java/org/springframework/cloud/alibaba/cloud/examples/HomeController.java @@ -0,0 +1,117 @@ +/* + * Copyright (C) 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 + * + * 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, + * 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 org.springframework.cloud.alibaba.cloud.examples; + +import com.alibaba.fescar.spring.annotation.GlobalTransactional; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.cloud.alibaba.cloud.examples.BusinessApplication.OrderService; +import org.springframework.cloud.alibaba.cloud.examples.BusinessApplication.StorageService; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.RestTemplate; + +/** + * @author xiaojing + */ +@RestController +public class HomeController { + + private static final Logger LOGGER = LoggerFactory.getLogger(HomeController.class); + + private static final String SUCCESS = "SUCCESS"; + private static final String FAIL = "FAIL"; + private static final String USER_ID = "U100001"; + private static final String COMMODITY_CODE = "C00321"; + private static final int ORDER_COUNT = 2; + + private final RestTemplate restTemplate; + private final OrderService orderService; + private final StorageService storageService; + + public HomeController(RestTemplate restTemplate, OrderService orderService, + StorageService storageService) { + this.restTemplate = restTemplate; + this.orderService = orderService; + this.storageService = storageService; + } + + @GlobalTransactional(timeoutMills = 300000, name = "spring-cloud-demo-tx") + @RequestMapping(value = "/fescar/rest", method = RequestMethod.GET, produces = "application/json") + public String rest() { + + String result = restTemplate.getForObject( + "http://127.0.0.1:18082/storage/" + COMMODITY_CODE + "/" + ORDER_COUNT, + String.class); + + if (!SUCCESS.equals(result)) { + throw new RuntimeException(); + } + + String url = "http://127.0.0.1:18083/order"; + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); + + MultiValueMap map = new LinkedMultiValueMap(); + map.add("userId", USER_ID); + map.add("commodityCode", COMMODITY_CODE); + map.add("orderCount", ORDER_COUNT + ""); + + HttpEntity> request = new HttpEntity>( + map, headers); + + ResponseEntity response = restTemplate.postForEntity(url, request, + String.class); + + result = response.getBody(); + + if (!SUCCESS.equals(result)) { + throw new RuntimeException(); + } + + return SUCCESS; + } + + @GlobalTransactional(timeoutMills = 300000, name = "spring-cloud-demo-tx") + @RequestMapping(value = "/fescar/feign", method = RequestMethod.GET, produces = "application/json") + public String feign() { + + String result = storageService.storage(COMMODITY_CODE, ORDER_COUNT); + + if (!SUCCESS.equals(result)) { + throw new RuntimeException(); + } + + result = orderService.order(USER_ID, COMMODITY_CODE, ORDER_COUNT); + + if (!SUCCESS.equals(result)) { + throw new RuntimeException(); + } + + return SUCCESS; + + } + +} diff --git a/spring-cloud-alibaba-examples/fescar-example/business-service/src/main/java/org/springframework/cloud/alibaba/cloud/examples/Order.java b/spring-cloud-alibaba-examples/fescar-example/business-service/src/main/java/org/springframework/cloud/alibaba/cloud/examples/Order.java new file mode 100644 index 00000000..6594793a --- /dev/null +++ b/spring-cloud-alibaba-examples/fescar-example/business-service/src/main/java/org/springframework/cloud/alibaba/cloud/examples/Order.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 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 + * + * 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, + * 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 org.springframework.cloud.alibaba.cloud.examples; + +import java.io.Serializable; + +public class Order implements Serializable { + public long id; + public String userId; + public String commodityCode; + public int count; + public int money; + + @Override + public String toString() { + return "Order{" + "id=" + id + ", userId='" + userId + '\'' + ", commodityCode='" + + commodityCode + '\'' + ", count=" + count + ", money=" + money + '}'; + } +} diff --git a/spring-cloud-alibaba-examples/fescar-example/business-service/src/main/resources/application.conf b/spring-cloud-alibaba-examples/fescar-example/business-service/src/main/resources/application.conf new file mode 100644 index 00000000..65b69508 --- /dev/null +++ b/spring-cloud-alibaba-examples/fescar-example/business-service/src/main/resources/application.conf @@ -0,0 +1,30 @@ +transport { + # tcp udt unix-domain-socket + type = "TCP" + #NIO NATIVE + server = "NIO" + #thread factory for netty + thread-factory { + boss-thread-prefix = "NettyBoss" + worker-thread-prefix = "NettyServerNIOWorker" + server-executor-thread-prefix = "NettyServerBizHandler" + share-boss-worker = false + client-selector-thread-prefix = "NettyClientSelector" + client-selector-thread-size = 1 + client-worker-thread-prefix = "NettyClientWorkerThread" + # netty boss thread size,will not be used for UDT + boss-thread-size = 1 + #auto default pin or 8 + worker-thread-size = 8 + } +} +service { + #vgroup->rgroup + vgroup_mapping.business-service-fescar-service-group = "localRgroup" + #only support single node + localRgroup.grouplist = "127.0.0.1:8091" + #degrade current not support + enableDegrade = false + #disable + disable = false +} diff --git a/spring-cloud-alibaba-examples/fescar-example/business-service/src/main/resources/application.properties b/spring-cloud-alibaba-examples/fescar-example/business-service/src/main/resources/application.properties new file mode 100644 index 00000000..1832ce6f --- /dev/null +++ b/spring-cloud-alibaba-examples/fescar-example/business-service/src/main/resources/application.properties @@ -0,0 +1,8 @@ +server.port=18081 +spring.application.name=business-service +# The following configuration can be omitted. + +#feign.hystrix.enabled=true +#feign.sentinel.enabled=true + +logging.level.com.alibaba.fescar=debug \ No newline at end of file diff --git a/spring-cloud-alibaba-examples/fescar-example/order-service/pom.xml b/spring-cloud-alibaba-examples/fescar-example/order-service/pom.xml new file mode 100644 index 00000000..5e771690 --- /dev/null +++ b/spring-cloud-alibaba-examples/fescar-example/order-service/pom.xml @@ -0,0 +1,63 @@ + + + + spring-cloud-alibaba-examples + org.springframework.cloud + 0.1.2.BUILD-SNAPSHOT + ../../pom.xml + + 4.0.0 + order-service + + + + org.springframework.cloud + spring-cloud-starter-alibaba-fescar + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.boot + spring-boot-starter-jdbc + + + + mysql + mysql-connector-java + + + + + + + + org.codehaus.mojo + cobertura-maven-plugin + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + org.codehaus.mojo + cobertura-maven-plugin + false + + true + + + + + + \ No newline at end of file diff --git a/spring-cloud-alibaba-examples/fescar-example/order-service/src/main/java/org/springframework/cloud/alibaba/cloud/examples/DatabaseConfiguration.java b/spring-cloud-alibaba-examples/fescar-example/order-service/src/main/java/org/springframework/cloud/alibaba/cloud/examples/DatabaseConfiguration.java new file mode 100644 index 00000000..4519a37a --- /dev/null +++ b/spring-cloud-alibaba-examples/fescar-example/order-service/src/main/java/org/springframework/cloud/alibaba/cloud/examples/DatabaseConfiguration.java @@ -0,0 +1,91 @@ +/* + * Copyright (C) 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 + * + * 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, + * 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 org.springframework.cloud.alibaba.cloud.examples; + +import java.sql.SQLException; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.core.env.Environment; +import org.springframework.jdbc.core.JdbcTemplate; + +import com.alibaba.druid.pool.DruidDataSource; +import com.alibaba.fescar.rm.datasource.DataSourceProxy; + +/** + * @author xiaojing + */ +@Configuration +public class DatabaseConfiguration { + + private final ApplicationContext applicationContext; + + public DatabaseConfiguration(ApplicationContext applicationContext) { + this.applicationContext = applicationContext; + } + + @Bean(initMethod = "init", destroyMethod = "close") + @Primary + public DruidDataSource druidDataSource() throws SQLException { + + Environment env = applicationContext.getEnvironment(); + + String ip = env.getProperty("mysql.server.ip"); + String port = env.getProperty("mysql.server.port"); + String dbName = env.getProperty("mysql.db.name"); + + String userName = env.getProperty("mysql.user.name"); + String password = env.getProperty("mysql.user.password"); + + DruidDataSource druidDataSource = new DruidDataSource(); + druidDataSource.setUrl("jdbc:mysql://" + ip + ":" + port + "/" + dbName); + druidDataSource.setUsername(userName); + druidDataSource.setPassword(password); + druidDataSource.setDriverClassName("com.mysql.jdbc.Driver"); + druidDataSource.setInitialSize(0); + druidDataSource.setMaxActive(180); + druidDataSource.setMaxWait(60000); + druidDataSource.setMinIdle(0); + druidDataSource.setValidationQuery("Select 'x' from DUAL"); + druidDataSource.setTestOnBorrow(false); + druidDataSource.setTestOnReturn(false); + druidDataSource.setTestWhileIdle(true); + druidDataSource.setTimeBetweenEvictionRunsMillis(60000); + druidDataSource.setMinEvictableIdleTimeMillis(25200000); + druidDataSource.setRemoveAbandoned(true); + druidDataSource.setRemoveAbandonedTimeout(1800); + druidDataSource.setLogAbandoned(true); + druidDataSource.setFilters("mergeStat"); + return druidDataSource; + } + + @Bean + public DataSourceProxy dataSourceProxy(DruidDataSource druidDataSource) { + return new DataSourceProxy(druidDataSource); + } + + @Bean + public JdbcTemplate jdbcTemplate(DataSourceProxy dataSourceProxy) { + JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSourceProxy); + + jdbcTemplate.execute("TRUNCATE TABLE order_tbl"); + + return jdbcTemplate; + } + +} diff --git a/spring-cloud-alibaba-examples/fescar-example/order-service/src/main/java/org/springframework/cloud/alibaba/cloud/examples/OderApplication.java b/spring-cloud-alibaba-examples/fescar-example/order-service/src/main/java/org/springframework/cloud/alibaba/cloud/examples/OderApplication.java new file mode 100644 index 00000000..1ab0dab1 --- /dev/null +++ b/spring-cloud-alibaba-examples/fescar-example/order-service/src/main/java/org/springframework/cloud/alibaba/cloud/examples/OderApplication.java @@ -0,0 +1,39 @@ +/* + * Copyright (C) 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 + * + * 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, + * 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 org.springframework.cloud.alibaba.cloud.examples; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.web.client.RestTemplate; + +/** + * @author xiaojing + */ +@SpringBootApplication +public class OderApplication { + + public static void main(String[] args) { + SpringApplication.run(OderApplication.class, args); + } + + @Bean + public RestTemplate restTemplate() { + return new RestTemplate(); + } + +} diff --git a/spring-cloud-alibaba-examples/fescar-example/order-service/src/main/java/org/springframework/cloud/alibaba/cloud/examples/Order.java b/spring-cloud-alibaba-examples/fescar-example/order-service/src/main/java/org/springframework/cloud/alibaba/cloud/examples/Order.java new file mode 100644 index 00000000..6594793a --- /dev/null +++ b/spring-cloud-alibaba-examples/fescar-example/order-service/src/main/java/org/springframework/cloud/alibaba/cloud/examples/Order.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 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 + * + * 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, + * 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 org.springframework.cloud.alibaba.cloud.examples; + +import java.io.Serializable; + +public class Order implements Serializable { + public long id; + public String userId; + public String commodityCode; + public int count; + public int money; + + @Override + public String toString() { + return "Order{" + "id=" + id + ", userId='" + userId + '\'' + ", commodityCode='" + + commodityCode + '\'' + ", count=" + count + ", money=" + money + '}'; + } +} diff --git a/spring-cloud-alibaba-examples/fescar-example/order-service/src/main/java/org/springframework/cloud/alibaba/cloud/examples/OrderController.java b/spring-cloud-alibaba-examples/fescar-example/order-service/src/main/java/org/springframework/cloud/alibaba/cloud/examples/OrderController.java new file mode 100644 index 00000000..2e0e0f81 --- /dev/null +++ b/spring-cloud-alibaba-examples/fescar-example/order-service/src/main/java/org/springframework/cloud/alibaba/cloud/examples/OrderController.java @@ -0,0 +1,131 @@ +/* + * Copyright (C) 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 + * + * 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, + * 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 org.springframework.cloud.alibaba.cloud.examples; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.util.Random; + +import com.alibaba.fescar.core.context.RootContext; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.PreparedStatementCreator; +import org.springframework.jdbc.support.GeneratedKeyHolder; +import org.springframework.jdbc.support.KeyHolder; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.RestTemplate; + +/** + * @author xiaojing + */ +@RestController +public class OrderController { + + private static final Logger LOGGER = LoggerFactory.getLogger(OrderController.class); + private static final String SUCCESS = "SUCCESS"; + private static final String FAIL = "FAIL"; + private static final String USER_ID = "U100001"; + private static final String COMMODITY_CODE = "C00321"; + + private final JdbcTemplate jdbcTemplate; + private final RestTemplate restTemplate; + private Random random; + + public OrderController(JdbcTemplate jdbcTemplate, RestTemplate restTemplate) { + this.jdbcTemplate = jdbcTemplate; + this.restTemplate = restTemplate; + this.random = new Random(); + } + + @RequestMapping(value = "/order", method = RequestMethod.POST, produces = "application/json") + public String order(String userId, String commodityCode, int orderCount) { + LOGGER.info("Order Service Begin ... xid: " + RootContext.getXID()); + + int orderMoney = calculate(commodityCode, orderCount); + + invokerAccountService(orderMoney); + + final Order order = new Order(); + order.userId = userId; + order.commodityCode = commodityCode; + order.count = orderCount; + order.money = orderMoney; + + KeyHolder keyHolder = new GeneratedKeyHolder(); + + int result = jdbcTemplate.update(new PreparedStatementCreator() { + + @Override + public PreparedStatement createPreparedStatement(Connection con) + throws SQLException { + PreparedStatement pst = con.prepareStatement( + "insert into order_tbl (user_id, commodity_code, count, money) values (?, ?, ?, ?)", + PreparedStatement.RETURN_GENERATED_KEYS); + pst.setObject(1, order.userId); + pst.setObject(2, order.commodityCode); + pst.setObject(3, order.count); + pst.setObject(4, order.money); + return pst; + } + }, keyHolder); + + order.id = (long) keyHolder.getKey(); + + if (random.nextBoolean()) { + throw new RuntimeException("this is a mock Exception"); + } + + LOGGER.info("Order Service End ... Created " + order); + + if (result == 1) { + return SUCCESS; + } + return FAIL; + } + + private int calculate(String commodityId, int orderCount) { + return 2 * orderCount; + } + + private void invokerAccountService(int orderMoney) { + String url = "http://127.0.0.1:18084/account"; + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); + + MultiValueMap map = new LinkedMultiValueMap(); + + map.add("userId", USER_ID); + map.add("money", orderMoney + ""); + + HttpEntity> request = new HttpEntity>( + map, headers); + + ResponseEntity response = restTemplate.postForEntity(url, request, + String.class); + } +} diff --git a/spring-cloud-alibaba-examples/fescar-example/order-service/src/main/resources/application.conf b/spring-cloud-alibaba-examples/fescar-example/order-service/src/main/resources/application.conf new file mode 100644 index 00000000..c298ca0c --- /dev/null +++ b/spring-cloud-alibaba-examples/fescar-example/order-service/src/main/resources/application.conf @@ -0,0 +1,30 @@ +transport { + # tcp udt unix-domain-socket + type = "TCP" + #NIO NATIVE + server = "NIO" + #thread factory for netty + thread-factory { + boss-thread-prefix = "NettyBoss" + worker-thread-prefix = "NettyServerNIOWorker" + server-executor-thread-prefix = "NettyServerBizHandler" + share-boss-worker = false + client-selector-thread-prefix = "NettyClientSelector" + client-selector-thread-size = 1 + client-worker-thread-prefix = "NettyClientWorkerThread" + # netty boss thread size,will not be used for UDT + boss-thread-size = 1 + #auto default pin or 8 + worker-thread-size = 8 + } +} +service { + #vgroup->rgroup + vgroup_mapping.order-service-fescar-service-group = "localRgroup" + #only support single node + localRgroup.grouplist = "127.0.0.1:8091" + #degrade current not support + enableDegrade = false + #disable + disable = false +} diff --git a/spring-cloud-alibaba-examples/fescar-example/order-service/src/main/resources/application.properties b/spring-cloud-alibaba-examples/fescar-example/order-service/src/main/resources/application.properties new file mode 100644 index 00000000..f3e417d8 --- /dev/null +++ b/spring-cloud-alibaba-examples/fescar-example/order-service/src/main/resources/application.properties @@ -0,0 +1,9 @@ +spring.application.name=order-service +server.port=18083 + +mysql.server.ip=127.0.0.1 +mysql.server.port=3306 +mysql.db.name=demo + +mysql.user.name=xxxxx +mysql.user.password=xxxxx \ No newline at end of file diff --git a/spring-cloud-alibaba-examples/fescar-example/readme-zh.md b/spring-cloud-alibaba-examples/fescar-example/readme-zh.md new file mode 100644 index 00000000..e93f6866 --- /dev/null +++ b/spring-cloud-alibaba-examples/fescar-example/readme-zh.md @@ -0,0 +1,156 @@ +# Fescar Example + +## 项目说明 + + +本项目演示如何使用 Fescar Starter 完成 Spring Cloud 应用的分布式事务接入。 + +[Fescar](https://github.com/alibaba/fescar) 是 阿里巴巴 开源的 分布式事务中间件,以 高效 并且对业务 0 侵入 的方式,解决 微服务 场景下面临的分布式事务问题。 + + + +## 准备工作 + +在运行此示例之前,你需要先完成如下几步准备工作: + +1. 配置数据库 + +1. 创建 UNDO_LOG 表 + +1. 创建 示例中 业务所需要的数据库表 + +1. 启动 Fescar Server + + +### 配置数据库 + +首先,你需要有一个支持 InnoDB 引擎的 MySQL 数据库。 + +**注意**: 实际上,Fescar 支持不同的应用使用完全不相干的数据库,但是这里为了简单地演示一个原理,所以我们选择了只使用一个数据库。 + +将 `account-server`、`order-service`、`storage-service` 这三个应用中的 resources 目录下的 `application.properties` 文件中的如下配置修改成你运行环境中的实际配置。 + +``` +mysql.server.ip=your mysql server ip address +mysql.server.port=your mysql server listening port +mysql.db.name=your database name for test + +mysql.user.name=your mysql server username +mysql.user.password=your mysql server password + +``` + +### 创建 UNDO_LOG 表 + +[Fescar AT 模式]() 需要使用到 UNDO_LOG 表。 + +``` $sql +CREATE TABLE `undo_log` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `branch_id` bigint(20) NOT NULL, + `xid` varchar(100) NOT NULL, + `rollback_info` longblob NOT NULL, + `log_status` int(11) NOT NULL, + `log_created` datetime NOT NULL, + `log_modified` datetime NOT NULL, + `ext` varchar(100) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `idx_unionkey` (`xid`,`branch_id`) +) ENGINE=InnoDB AUTO_INCREMENT=159 DEFAULT CHARSET=utf8 +``` + +### 创建 示例中 业务所需要的数据库表 + +```$sql +DROP TABLE IF EXISTS `storage_tbl`; +CREATE TABLE `storage_tbl` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `commodity_code` varchar(255) DEFAULT NULL, + `count` int(11) DEFAULT 0, + PRIMARY KEY (`id`), + UNIQUE KEY (`commodity_code`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + + +DROP TABLE IF EXISTS `order_tbl`; +CREATE TABLE `order_tbl` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `user_id` varchar(255) DEFAULT NULL, + `commodity_code` varchar(255) DEFAULT NULL, + `count` int(11) DEFAULT 0, + `money` int(11) DEFAULT 0, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + + +DROP TABLE IF EXISTS `account_tbl`; +CREATE TABLE `account_tbl` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `user_id` varchar(255) DEFAULT NULL, + `money` int(11) DEFAULT 0, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +``` + +### 启动 Fescar Server + +点击这个页面 [https://github.com/alibaba/fescar/releases](https://github.com/alibaba/fescar/releases),下载最新版本的 Fescar Server 端. + + +进入解压之后的 bin 目录,执行如下命令来启动 + +```$shell +sh fescar-server.sh $LISTEN_PORT $PATH_FOR_PERSISTENT_DATA +``` + +在这个示例中,采用如下命令来启动 Fescar Server + +```$shell +sh fescar-server.sh 8091 ~/fescar/data/ +``` + +**注意** 如果你修改了端口号,那么记得需要在各个示例工程中的 `application.conf` 文件中,修改 grouplist 的值。 + + +## 运行示例 + +分别运行 `account-server`、`order-service`、`storage-service` 和 `business-service` 这三个应用的 Main 函数,启动示例。 + +启动示例后,通过 HTTP 的 GET 方法访问如下两个 URL,可以分别验证在 `business-service` 中 通过 RestTemplate 和 FeignClient 调用其他服务的场景。 + +```$xslt +http://127.0.0.1:18081/fescar/feign + +http://127.0.0.1:18081/fescar/rest +``` + +## 如何验证分布式事务成功? + +### Xid 信息是否成功传递 + +在 `account-server`、`order-service` 和 `storage-service` 三个 服务的 Controller 中,第一个执行的逻辑都是输出 RootContext 中的 Xid 信息,如果看到都输出了正确的 Xid 信息,即每次都发生变化,且同一次调用中所有服务的 Xid 都一致。则表明 Fescar 的 Xid 的传递和还原是正常的。 + +### 数据库中数据是否一致 + +在本示例中,我们模拟了一个用户购买货物的场景,StorageService 负责扣减库存数量,OrderService 负责保存订单,AccountService 负责扣减用户账户余额。 + +为了演示样例,我们在 OrderService 和 AccountService 中 使用 Random.nextBoolean() 的方式来随机抛出异常,模拟了在服务调用时随机发生异常的场景。 + +如果分布式事务生效的话, 那么以下等式应该成立 + + +- 用户原始金额(1000) = 用户现存的金额 + 货物单价 (2) * 订单数量 * 每单的货物数量(2) + +- 货物的初始数量(100) = 货物的现存数量 + 订单数量 * 每单的货物数量(2) + +## 对 Spring Cloud 支持点 + +- 通过 Spring MVC 提供服务的服务提供者,在收到 header 中含有 Fescar 信息的 HTTP 请求时,可以自动还原 Fescar 上下文。 + +- 支持服务调用者通过 RestTemplate 调用时,自动传递 Fescar 上下文。 + +- 支持服务调用者通过 FeignClient 调用时,自动传递 Fescar 上下文。 + +- 支持 FeignClient 和 Hystrix 同时使用的场景。 + +- 支持 FeignClient 和 Sentinel 同时使用的场景。 diff --git a/spring-cloud-alibaba-examples/fescar-example/storage-service/pom.xml b/spring-cloud-alibaba-examples/fescar-example/storage-service/pom.xml new file mode 100644 index 00000000..18920924 --- /dev/null +++ b/spring-cloud-alibaba-examples/fescar-example/storage-service/pom.xml @@ -0,0 +1,68 @@ + + + + spring-cloud-alibaba-examples + org.springframework.cloud + 0.1.2.BUILD-SNAPSHOT + ../../pom.xml + + 4.0.0 + storage-service + + + + org.springframework.cloud + spring-cloud-starter-alibaba-fescar + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-actuator + + + com.alibaba + druid + 1.1.10 + + + org.springframework.boot + spring-boot-starter-jdbc + + + + mysql + mysql-connector-java + + + + + + + + org.codehaus.mojo + cobertura-maven-plugin + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + org.codehaus.mojo + cobertura-maven-plugin + false + + true + + + + + + \ No newline at end of file diff --git a/spring-cloud-alibaba-examples/fescar-example/storage-service/src/main/java/org/springframework/cloud/alibaba/cloud/examples/DatabaseConfiguration.java b/spring-cloud-alibaba-examples/fescar-example/storage-service/src/main/java/org/springframework/cloud/alibaba/cloud/examples/DatabaseConfiguration.java new file mode 100644 index 00000000..9f41dc24 --- /dev/null +++ b/spring-cloud-alibaba-examples/fescar-example/storage-service/src/main/java/org/springframework/cloud/alibaba/cloud/examples/DatabaseConfiguration.java @@ -0,0 +1,96 @@ +/* + * Copyright (C) 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 + * + * 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, + * 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 org.springframework.cloud.alibaba.cloud.examples; + +import java.sql.SQLException; + +import com.alibaba.druid.pool.DruidDataSource; +import com.alibaba.fescar.rm.datasource.DataSourceProxy; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.core.env.Environment; +import org.springframework.jdbc.core.JdbcTemplate; + +/** + * @author xiaojing + */ +@Configuration +public class DatabaseConfiguration { + + private final ApplicationContext applicationContext; + + public DatabaseConfiguration(ApplicationContext applicationContext) { + this.applicationContext = applicationContext; + } + + @Bean(initMethod = "init", destroyMethod = "close") + @Primary + public DruidDataSource druidDataSource() throws SQLException { + + Environment environment = applicationContext.getEnvironment(); + + String ip = environment.getProperty("mysql.server.ip"); + String port = environment.getProperty("mysql.server.port"); + String dbName = environment.getProperty("mysql.db.name"); + + String userName = environment.getProperty("mysql.user.name"); + String password = environment.getProperty("mysql.user.password"); + + DruidDataSource druidDataSource = new DruidDataSource(); + druidDataSource.setUrl("jdbc:mysql://" + ip + ":" + port + "/" + dbName); + druidDataSource.setUsername(userName); + druidDataSource.setPassword(password); + druidDataSource.setDriverClassName("com.mysql.jdbc.Driver"); + druidDataSource.setInitialSize(0); + druidDataSource.setMaxActive(180); + druidDataSource.setMaxWait(60000); + druidDataSource.setMinIdle(0); + druidDataSource.setValidationQuery("Select 'x' from DUAL"); + druidDataSource.setTestOnBorrow(false); + druidDataSource.setTestOnReturn(false); + druidDataSource.setTestWhileIdle(true); + druidDataSource.setTimeBetweenEvictionRunsMillis(60000); + druidDataSource.setMinEvictableIdleTimeMillis(25200000); + druidDataSource.setRemoveAbandoned(true); + druidDataSource.setRemoveAbandonedTimeout(1800); + druidDataSource.setLogAbandoned(true); + druidDataSource.setFilters("mergeStat"); + return druidDataSource; + } + + @Bean + public DataSourceProxy dataSourceProxy(DruidDataSource druidDataSource) { + return new DataSourceProxy(druidDataSource); + } + + @Bean + public JdbcTemplate jdbcTemplate(DataSourceProxy dataSourceProxy) { + + JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSourceProxy); + + jdbcTemplate.update("delete from storage_tbl where commodity_code = 'C00321'"); + jdbcTemplate.update( + "insert into storage_tbl(commodity_code, count) values ('C00321', 100)"); + + return jdbcTemplate; + + } + +} diff --git a/spring-cloud-alibaba-examples/fescar-example/storage-service/src/main/java/org/springframework/cloud/alibaba/cloud/examples/StorageApplication.java b/spring-cloud-alibaba-examples/fescar-example/storage-service/src/main/java/org/springframework/cloud/alibaba/cloud/examples/StorageApplication.java new file mode 100644 index 00000000..94bbac7f --- /dev/null +++ b/spring-cloud-alibaba-examples/fescar-example/storage-service/src/main/java/org/springframework/cloud/alibaba/cloud/examples/StorageApplication.java @@ -0,0 +1,32 @@ +/* + * Copyright (C) 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 + * + * 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, + * 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 org.springframework.cloud.alibaba.cloud.examples; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * @author xiaojing + */ +@SpringBootApplication +public class StorageApplication { + + public static void main(String[] args) { + SpringApplication.run(StorageApplication.class, args); + } + +} diff --git a/spring-cloud-alibaba-examples/fescar-example/storage-service/src/main/java/org/springframework/cloud/alibaba/cloud/examples/StorageController.java b/spring-cloud-alibaba-examples/fescar-example/storage-service/src/main/java/org/springframework/cloud/alibaba/cloud/examples/StorageController.java new file mode 100644 index 00000000..fd97ab2c --- /dev/null +++ b/spring-cloud-alibaba-examples/fescar-example/storage-service/src/main/java/org/springframework/cloud/alibaba/cloud/examples/StorageController.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 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 + * + * 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, + * 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 org.springframework.cloud.alibaba.cloud.examples; + +import com.alibaba.fescar.core.context.RootContext; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +/** + * @author xiaojing + */ +@RestController +public class StorageController { + + private static final Logger LOGGER = LoggerFactory.getLogger(StorageController.class); + + private static final String SUCCESS = "SUCCESS"; + private static final String FAIL = "FAIL"; + + private final JdbcTemplate jdbcTemplate; + + public StorageController(JdbcTemplate jdbcTemplate) { + this.jdbcTemplate = jdbcTemplate; + } + + @RequestMapping(value = "/storage/{commodityCode}/{count}", method = RequestMethod.GET, produces = "application/json") + public String echo(@PathVariable String commodityCode, @PathVariable int count) { + LOGGER.info("Storage Service Begin ... xid: " + RootContext.getXID()); + int result = jdbcTemplate.update( + "update storage_tbl set count = count - ? where commodity_code = ?", + new Object[] { count, commodityCode }); + LOGGER.info("Storage Service End ... "); + if (result == 1) { + return SUCCESS; + } + return FAIL; + } +} diff --git a/spring-cloud-alibaba-examples/fescar-example/storage-service/src/main/resources/application.conf b/spring-cloud-alibaba-examples/fescar-example/storage-service/src/main/resources/application.conf new file mode 100644 index 00000000..4bc5989e --- /dev/null +++ b/spring-cloud-alibaba-examples/fescar-example/storage-service/src/main/resources/application.conf @@ -0,0 +1,30 @@ +transport { + # tcp udt unix-domain-socket + type = "TCP" + #NIO NATIVE + server = "NIO" + #thread factory for netty + thread-factory { + boss-thread-prefix = "NettyBoss" + worker-thread-prefix = "NettyServerNIOWorker" + server-executor-thread-prefix = "NettyServerBizHandler" + share-boss-worker = false + client-selector-thread-prefix = "NettyClientSelector" + client-selector-thread-size = 1 + client-worker-thread-prefix = "NettyClientWorkerThread" + # netty boss thread size,will not be used for UDT + boss-thread-size = 1 + #auto default pin or 8 + worker-thread-size = 8 + } +} +service { + #vgroup->rgroup + vgroup_mapping.storage-service-fescar-service-group = "localRgroup" + #only support single node + localRgroup.grouplist = "127.0.0.1:8091" + #degrade current not support + enableDegrade = false + #disable + disable = false +} diff --git a/spring-cloud-alibaba-examples/fescar-example/storage-service/src/main/resources/application.properties b/spring-cloud-alibaba-examples/fescar-example/storage-service/src/main/resources/application.properties new file mode 100644 index 00000000..832eaecd --- /dev/null +++ b/spring-cloud-alibaba-examples/fescar-example/storage-service/src/main/resources/application.properties @@ -0,0 +1,9 @@ +spring.application.name=storage-service +server.port=18082 + +mysql.server.ip=127.0.0.1 +mysql.server.port=3306 +mysql.db.name=demo + +mysql.user.name=xxxxx +mysql.user.password=xxxxx \ No newline at end of file diff --git a/spring-cloud-alibaba-examples/pom.xml b/spring-cloud-alibaba-examples/pom.xml index 451e8c61..f0b76037 100644 --- a/spring-cloud-alibaba-examples/pom.xml +++ b/spring-cloud-alibaba-examples/pom.xml @@ -26,6 +26,10 @@ ans-example/ans-consumer-feign-example ans-example/ans-consumer-ribbon-example ans-example/ans-provider-example + fescar-example/business-service + fescar-example/order-service + fescar-example/storage-service + fescar-example/account-service acm-example/acm-local-example rocketmq-example env-extension diff --git a/spring-cloud-alibaba-fescar/pom.xml b/spring-cloud-alibaba-fescar/pom.xml new file mode 100644 index 00000000..d7cffa17 --- /dev/null +++ b/spring-cloud-alibaba-fescar/pom.xml @@ -0,0 +1,110 @@ + + + + + org.springframework.cloud + spring-cloud-alibaba + 0.1.2.BUILD-SNAPSHOT + + 4.0.0 + + org.springframework.cloud + spring-cloud-alibaba-fescar + Spring Cloud Alibaba Fescar + + + + + com.alibaba.fescar + fescar-core + + + com.alibaba.fescar + fescar-common + + + com.alibaba.fescar + fescar-spring + + + com.alibaba.fescar + fescar-rm-datasource + + + + org.springframework.cloud + spring-cloud-starter-feign + provided + true + + + org.springframework.cloud + spring-cloud-starter-alibaba-sentinel + provided + true + + + + org.springframework.cloud + spring-cloud-commons + true + + + + org.springframework.cloud + spring-cloud-starter-netflix-ribbon + provided + true + + + + + + org.springframework.boot + spring-boot-starter-aop + + + + org.springframework.boot + spring-boot-actuator + provided + true + + + + org.springframework.boot + spring-boot-configuration-processor + provided + true + + + + org.springframework.boot + spring-boot + provided + true + + + + org.springframework.boot + spring-boot-autoconfigure + provided + true + + + org.springframework.boot + spring-boot-starter-web + provided + true + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + diff --git a/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/FescarProperties.java b/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/FescarProperties.java new file mode 100644 index 00000000..f7847d96 --- /dev/null +++ b/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/FescarProperties.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 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 + * + * 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, + * 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 org.springframework.cloud.alibaba.fescar; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * @author xiaojing + */ +@ConfigurationProperties("spring.cloud.alibaba.fescar") +public class FescarProperties { + + // todo support config Fescar server information + + /** + * Fescar tx service group.default is ${spring.application.name}-fescar-service-group. + */ + private String txServiceGroup; + + public String getTxServiceGroup() { + return txServiceGroup; + } + + public void setTxServiceGroup(String txServiceGroup) { + this.txServiceGroup = txServiceGroup; + } + +} diff --git a/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/GlobalTransactionAutoConfiguration.java b/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/GlobalTransactionAutoConfiguration.java new file mode 100644 index 00000000..d876ad3b --- /dev/null +++ b/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/GlobalTransactionAutoConfiguration.java @@ -0,0 +1,60 @@ +/* + * Copyright (C) 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 + * + * 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, + * 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 org.springframework.cloud.alibaba.fescar; + +import com.alibaba.fescar.spring.annotation.GlobalTransactionScanner; + +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.util.StringUtils; + +/** + * @author xiaojing + */ + +@Configuration +@EnableConfigurationProperties(FescarProperties.class) +public class GlobalTransactionAutoConfiguration { + + private final ApplicationContext applicationContext; + + private final FescarProperties fescarProperties; + + public GlobalTransactionAutoConfiguration(ApplicationContext applicationContext, + FescarProperties fescarProperties) { + this.applicationContext = applicationContext; + this.fescarProperties = fescarProperties; + } + + @Bean + public GlobalTransactionScanner globalTransactionScanner() { + + String applicationName = applicationContext.getEnvironment() + .getProperty("spring.application.name"); + + String txServiceGroup = fescarProperties.getTxServiceGroup(); + + if (StringUtils.isEmpty(txServiceGroup)) { + txServiceGroup = applicationName + "-fescar-service-group"; + fescarProperties.setTxServiceGroup(txServiceGroup); + } + + return new GlobalTransactionScanner(applicationName, txServiceGroup); + } +} diff --git a/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/feign/FescarBeanPostProcessor.java b/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/feign/FescarBeanPostProcessor.java new file mode 100644 index 00000000..02bd6c32 --- /dev/null +++ b/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/feign/FescarBeanPostProcessor.java @@ -0,0 +1,44 @@ +/* + * Copyright (C) 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 + * + * 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, + * 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 org.springframework.cloud.alibaba.fescar.feign; + +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.config.BeanPostProcessor; + +/** + * @author xiaojing + */ +final class FescarBeanPostProcessor implements BeanPostProcessor { + + private final FescarFeignObjectWrapper fescarFeignObjectWrapper; + + FescarBeanPostProcessor(FescarFeignObjectWrapper fescarFeignObjectWrapper) { + this.fescarFeignObjectWrapper = fescarFeignObjectWrapper; + } + + @Override + public Object postProcessBeforeInitialization(Object bean, String beanName) + throws BeansException { + return this.fescarFeignObjectWrapper.wrap(bean); + } + + @Override + public Object postProcessAfterInitialization(Object bean, String beanName) + throws BeansException { + return bean; + } +} \ No newline at end of file diff --git a/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/feign/FescarContextBeanPostProcessor.java b/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/feign/FescarContextBeanPostProcessor.java new file mode 100644 index 00000000..e71b495e --- /dev/null +++ b/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/feign/FescarContextBeanPostProcessor.java @@ -0,0 +1,59 @@ +/* + * Copyright (C) 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 + * + * 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, + * 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 org.springframework.cloud.alibaba.fescar.feign; + +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.BeanFactory; +import org.springframework.beans.factory.config.BeanPostProcessor; +import org.springframework.cloud.netflix.feign.FeignContext; + +/** + * @author xiaojing + */ +public class FescarContextBeanPostProcessor implements BeanPostProcessor { + + private final BeanFactory beanFactory; + private FescarFeignObjectWrapper fescarFeignObjectWrapper; + + FescarContextBeanPostProcessor(BeanFactory beanFactory) { + this.beanFactory = beanFactory; + } + + @Override + public Object postProcessBeforeInitialization(Object bean, String beanName) + throws BeansException { + if (bean instanceof FeignContext && !(bean instanceof FescarFeignContext)) { + return new FescarFeignContext(getFescarFeignObjectWrapper(), + (FeignContext) bean); + } + return bean; + } + + @Override + public Object postProcessAfterInitialization(Object bean, String beanName) + throws BeansException { + return bean; + } + + private FescarFeignObjectWrapper getFescarFeignObjectWrapper() { + if (this.fescarFeignObjectWrapper == null) { + this.fescarFeignObjectWrapper = this.beanFactory + .getBean(FescarFeignObjectWrapper.class); + } + return this.fescarFeignObjectWrapper; + } +} diff --git a/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/feign/FescarFeignBuilder.java b/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/feign/FescarFeignBuilder.java new file mode 100644 index 00000000..acab33ff --- /dev/null +++ b/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/feign/FescarFeignBuilder.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) 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 + * + * 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, + * 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 org.springframework.cloud.alibaba.fescar.feign; + +import org.springframework.beans.factory.BeanFactory; + +import feign.Feign; + +/** + * @author xiaojing + */ +final class FescarFeignBuilder { + + private FescarFeignBuilder() { + } + + static Feign.Builder builder(BeanFactory beanFactory) { + return Feign.builder().client(new FescarFeignClient(beanFactory)); + } +} diff --git a/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/feign/FescarFeignClient.java b/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/feign/FescarFeignClient.java new file mode 100644 index 00000000..9fc9d527 --- /dev/null +++ b/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/feign/FescarFeignClient.java @@ -0,0 +1,85 @@ +/* + * Copyright (C) 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 + * + * 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, + * 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 org.springframework.cloud.alibaba.fescar.feign; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.alibaba.fescar.core.context.RootContext; + +import org.springframework.beans.factory.BeanFactory; + +import feign.Client; +import feign.Request; +import feign.Response; +import org.springframework.util.StringUtils; + +/** + * @author xiaojing + */ +public class FescarFeignClient implements Client { + + private final Client delegate; + private final BeanFactory beanFactory; + + FescarFeignClient(BeanFactory beanFactory) { + this.beanFactory = beanFactory; + this.delegate = new Client.Default(null, null); + } + + FescarFeignClient(BeanFactory beanFactory, Client delegate) { + this.delegate = delegate; + this.beanFactory = beanFactory; + } + + @Override + public Response execute(Request request, Request.Options options) throws IOException { + + Request modifiedRequest = getModifyRequest(request); + + try { + return this.delegate.execute(modifiedRequest, options); + } + finally { + + } + } + + private Request getModifyRequest(Request request) { + + String xid = RootContext.getXID(); + + if (StringUtils.isEmpty(xid)) { + return request; + } + + Map> headers = new HashMap<>(); + headers.putAll(request.headers()); + + List fescarXid = new ArrayList<>(); + fescarXid.add(xid); + headers.put(RootContext.KEY_XID, fescarXid); + + return Request.create(request.method(), request.url(), headers, request.body(), + request.charset()); + } + +} \ No newline at end of file diff --git a/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/feign/FescarFeignClientAutoConfiguration.java b/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/feign/FescarFeignClientAutoConfiguration.java new file mode 100644 index 00000000..89a84409 --- /dev/null +++ b/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/feign/FescarFeignClientAutoConfiguration.java @@ -0,0 +1,85 @@ +/* + * Copyright (C) 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 + * + * 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, + * 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 org.springframework.cloud.alibaba.fescar.feign; + +import org.springframework.beans.factory.BeanFactory; +import org.springframework.boot.autoconfigure.AutoConfigureBefore; +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.netflix.feign.FeignAutoConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Scope; + +import feign.Client; +import feign.Feign; + +/** + * @author xiaojing + */ + +@Configuration +@ConditionalOnClass(Client.class) +@AutoConfigureBefore(FeignAutoConfiguration.class) +public class FescarFeignClientAutoConfiguration { + + @Bean + @Scope("prototype") + @ConditionalOnClass(name = "com.netflix.hystrix.HystrixCommand") + @ConditionalOnProperty(name = "feign.hystrix.enabled", havingValue = "true") + Feign.Builder feignHystrixBuilder(BeanFactory beanFactory) { + return FescarHystrixFeignBuilder.builder(beanFactory); + } + + @Bean + @Scope("prototype") + @ConditionalOnClass(name = "com.alibaba.csp.sentinel.SphU") + @ConditionalOnProperty(name = "feign.sentinel.enabled", havingValue = "true") + Feign.Builder feignSentinelBuilder(BeanFactory beanFactory) { + return FescarSentinelFeignBuilder.builder(beanFactory); + } + + @Bean + @ConditionalOnMissingBean + @Scope("prototype") + Feign.Builder feignBuilder(BeanFactory beanFactory) { + return FescarFeignBuilder.builder(beanFactory); + } + + @Configuration + protected static class FeignBeanPostProcessorConfiguration { + + @Bean + FescarBeanPostProcessor fescarBeanPostProcessor( + FescarFeignObjectWrapper fescarFeignObjectWrapper) { + return new FescarBeanPostProcessor(fescarFeignObjectWrapper); + } + + @Bean + FescarContextBeanPostProcessor fescarContextBeanPostProcessor( + BeanFactory beanFactory) { + return new FescarContextBeanPostProcessor(beanFactory); + } + + @Bean + FescarFeignObjectWrapper fescarFeignObjectWrapper(BeanFactory beanFactory) { + return new FescarFeignObjectWrapper(beanFactory); + } + } + +} \ No newline at end of file diff --git a/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/feign/FescarFeignContext.java b/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/feign/FescarFeignContext.java new file mode 100644 index 00000000..7a269e8b --- /dev/null +++ b/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/feign/FescarFeignContext.java @@ -0,0 +1,67 @@ +/* + * Copyright (C) 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 + * + * 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, + * 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 org.springframework.cloud.alibaba.fescar.feign; + +import java.util.HashMap; +import java.util.Map; + +import feign.Client; +import org.springframework.cloud.netflix.feign.FeignContext; + +/** + * + * @author xiaojing + */ +public class FescarFeignContext extends FeignContext { + + private final FescarFeignObjectWrapper fescarFeignObjectWrapper; + private final FeignContext delegate; + + FescarFeignContext(FescarFeignObjectWrapper fescarFeignObjectWrapper, + FeignContext delegate) { + this.fescarFeignObjectWrapper = fescarFeignObjectWrapper; + this.delegate = delegate; + } + + @Override + public T getInstance(String name, Class type) { + T object = this.delegate.getInstance(name, type); + if (object instanceof Client) { + return object; + } + return (T) this.fescarFeignObjectWrapper.wrap(object); + } + + @Override + public Map getInstances(String name, Class type) { + Map instances = this.delegate.getInstances(name, type); + if (instances == null) { + return null; + } + Map convertedInstances = new HashMap<>(); + for (Map.Entry entry : instances.entrySet()) { + if (entry.getValue() instanceof Client) { + convertedInstances.put(entry.getKey(), entry.getValue()); + } + else { + convertedInstances.put(entry.getKey(), + (T) this.fescarFeignObjectWrapper.wrap(entry.getValue())); + } + } + return convertedInstances; + } +} diff --git a/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/feign/FescarFeignObjectWrapper.java b/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/feign/FescarFeignObjectWrapper.java new file mode 100644 index 00000000..38a3a4ff --- /dev/null +++ b/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/feign/FescarFeignObjectWrapper.java @@ -0,0 +1,67 @@ +/* + * Copyright (C) 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 + * + * 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, + * 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 org.springframework.cloud.alibaba.fescar.feign; + +import org.springframework.beans.factory.BeanFactory; +import org.springframework.cloud.netflix.ribbon.SpringClientFactory; + +import feign.Client; +import org.springframework.cloud.netflix.feign.ribbon.CachingSpringLoadBalancerFactory; +import org.springframework.cloud.netflix.feign.ribbon.LoadBalancerFeignClient; + +/** + * @author xiaojing + */ +public class FescarFeignObjectWrapper { + + private final BeanFactory beanFactory; + + private CachingSpringLoadBalancerFactory cachingSpringLoadBalancerFactory; + private SpringClientFactory springClientFactory; + + FescarFeignObjectWrapper(BeanFactory beanFactory) { + this.beanFactory = beanFactory; + } + + Object wrap(Object bean) { + if (bean instanceof Client && !(bean instanceof FescarFeignClient)) { + if (bean instanceof LoadBalancerFeignClient) { + LoadBalancerFeignClient client = ((LoadBalancerFeignClient) bean); + return new FescarLoadBalancerFeignClient(client.getDelegate(), factory(), + clientFactory(), this.beanFactory); + } + return new FescarFeignClient(this.beanFactory, (Client) bean); + } + return bean; + } + + CachingSpringLoadBalancerFactory factory() { + if (this.cachingSpringLoadBalancerFactory == null) { + this.cachingSpringLoadBalancerFactory = this.beanFactory + .getBean(CachingSpringLoadBalancerFactory.class); + } + return this.cachingSpringLoadBalancerFactory; + } + + SpringClientFactory clientFactory() { + if (this.springClientFactory == null) { + this.springClientFactory = this.beanFactory + .getBean(SpringClientFactory.class); + } + return this.springClientFactory; + } +} diff --git a/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/feign/FescarHystrixFeignBuilder.java b/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/feign/FescarHystrixFeignBuilder.java new file mode 100644 index 00000000..b67a9d84 --- /dev/null +++ b/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/feign/FescarHystrixFeignBuilder.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 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 + * + * 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, + * 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 org.springframework.cloud.alibaba.fescar.feign; + +import feign.Retryer; +import feign.hystrix.HystrixFeign; +import org.springframework.beans.factory.BeanFactory; + +import feign.Feign; + +/** + * @author xiaojing + */ +final class FescarHystrixFeignBuilder { + + private FescarHystrixFeignBuilder() { + } + + static Feign.Builder builder(BeanFactory beanFactory) { + return HystrixFeign.builder().retryer(Retryer.NEVER_RETRY) + .client(new FescarFeignClient(beanFactory)); + } +} diff --git a/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/feign/FescarLoadBalancerFeignClient.java b/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/feign/FescarLoadBalancerFeignClient.java new file mode 100644 index 00000000..89f98580 --- /dev/null +++ b/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/feign/FescarLoadBalancerFeignClient.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 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 + * + * 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, + * 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 org.springframework.cloud.alibaba.fescar.feign; + +import java.io.IOException; + +import org.springframework.beans.factory.BeanFactory; +import org.springframework.cloud.netflix.ribbon.SpringClientFactory; + +import feign.Client; +import feign.Request; +import feign.Response; +import org.springframework.cloud.netflix.feign.ribbon.CachingSpringLoadBalancerFactory; +import org.springframework.cloud.netflix.feign.ribbon.LoadBalancerFeignClient; + +/** + * @author xiaojing + */ +public class FescarLoadBalancerFeignClient extends LoadBalancerFeignClient { + + private final BeanFactory beanFactory; + + FescarLoadBalancerFeignClient(Client delegate, + CachingSpringLoadBalancerFactory lbClientFactory, + SpringClientFactory clientFactory, BeanFactory beanFactory) { + super(wrap(delegate, beanFactory), lbClientFactory, clientFactory); + this.beanFactory = beanFactory; + } + + @Override + public Response execute(Request request, Request.Options options) throws IOException { + return super.execute(request, options); + } + + private static Client wrap(Client delegate, BeanFactory beanFactory) { + return (Client) new FescarFeignObjectWrapper(beanFactory).wrap(delegate); + } + +} diff --git a/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/feign/FescarSentinelFeignBuilder.java b/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/feign/FescarSentinelFeignBuilder.java new file mode 100644 index 00000000..0a5f7892 --- /dev/null +++ b/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/feign/FescarSentinelFeignBuilder.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 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 + * + * 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, + * 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 org.springframework.cloud.alibaba.fescar.feign; + +import org.springframework.beans.factory.BeanFactory; + +import feign.Feign; +import feign.Retryer; +import org.springframework.cloud.alibaba.sentinel.feign.SentinelFeign; + +/** + * @author xiaojing + */ +final class FescarSentinelFeignBuilder { + + private FescarSentinelFeignBuilder() { + } + + static Feign.Builder builder(BeanFactory beanFactory) { + return SentinelFeign.builder().retryer(Retryer.NEVER_RETRY) + .client(new FescarFeignClient(beanFactory)); + } +} diff --git a/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/feign/hystrix/FescarHystrixAutoConfiguration.java b/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/feign/hystrix/FescarHystrixAutoConfiguration.java new file mode 100644 index 00000000..f7db4b0d --- /dev/null +++ b/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/feign/hystrix/FescarHystrixAutoConfiguration.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 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 + * + * 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, + * 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 org.springframework.cloud.alibaba.fescar.feign.hystrix; + +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import com.netflix.hystrix.HystrixCommand; + +/** + * @author xiaojing + */ + +@Configuration +@ConditionalOnClass(HystrixCommand.class) +public class FescarHystrixAutoConfiguration { + + @Bean + FescarHystrixConcurrencyStrategy fescarHystrixConcurrencyStrategy() { + return new FescarHystrixConcurrencyStrategy(); + } + +} \ No newline at end of file diff --git a/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/feign/hystrix/FescarHystrixConcurrencyStrategy.java b/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/feign/hystrix/FescarHystrixConcurrencyStrategy.java new file mode 100644 index 00000000..e21ff168 --- /dev/null +++ b/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/feign/hystrix/FescarHystrixConcurrencyStrategy.java @@ -0,0 +1,80 @@ +/* + * Copyright (C) 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 + * + * 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, + * 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 org.springframework.cloud.alibaba.fescar.feign.hystrix; + +import java.util.concurrent.Callable; + +import com.alibaba.fescar.core.context.RootContext; + +import com.netflix.hystrix.strategy.HystrixPlugins; +import com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy; + +/** + * @author xiaojing + */ +public class FescarHystrixConcurrencyStrategy extends HystrixConcurrencyStrategy { + + private HystrixConcurrencyStrategy delegate; + + public FescarHystrixConcurrencyStrategy() { + this.delegate = HystrixPlugins.getInstance().getConcurrencyStrategy(); + HystrixPlugins.reset(); + HystrixPlugins.getInstance().registerConcurrencyStrategy(this); + } + + @Override + public Callable wrapCallable(Callable c) { + if (c instanceof FescarContextCallable) { + return c; + } + + Callable wrappedCallable; + if (this.delegate != null) { + wrappedCallable = this.delegate.wrapCallable(c); + } + else { + wrappedCallable = c; + } + if (wrappedCallable instanceof FescarContextCallable) { + return wrappedCallable; + } + + return new FescarContextCallable<>(wrappedCallable); + } + + private static class FescarContextCallable implements Callable { + + private final Callable actual; + private final String xid; + + FescarContextCallable(Callable actual) { + this.actual = actual; + this.xid = RootContext.getXID(); + } + + @Override + public K call() throws Exception { + try { + RootContext.bind(xid); + return actual.call(); + } + finally { + RootContext.unbind(); + } + } + + } +} diff --git a/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/rest/FescarRestTemplateAutoConfiguration.java b/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/rest/FescarRestTemplateAutoConfiguration.java new file mode 100644 index 00000000..91191ed0 --- /dev/null +++ b/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/rest/FescarRestTemplateAutoConfiguration.java @@ -0,0 +1,76 @@ +/* + * Copyright (C) 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 + * + * 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, + * 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. + */ +/* + * Copyright (C) 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 + * + * 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, + * 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 org.springframework.cloud.alibaba.fescar.rest; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import javax.annotation.PostConstruct; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.client.ClientHttpRequestInterceptor; +import org.springframework.web.client.RestTemplate; + +/** + * @author xiaojing + */ + +@Configuration +public class FescarRestTemplateAutoConfiguration { + + @Bean + public FescarRestTemplateInterceptor fescarRestTemplateInterceptor() { + return new FescarRestTemplateInterceptor(); + } + + @Autowired(required = false) + private Collection restTemplates; + + @Autowired + private FescarRestTemplateInterceptor fescarRestTemplateInterceptor; + + @PostConstruct + public void init() { + if (this.restTemplates != null) { + for (RestTemplate restTemplate : restTemplates) { + List interceptors = new ArrayList( + restTemplate.getInterceptors()); + interceptors.add(this.fescarRestTemplateInterceptor); + restTemplate.setInterceptors(interceptors); + } + } + } + +} diff --git a/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/rest/FescarRestTemplateInterceptor.java b/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/rest/FescarRestTemplateInterceptor.java new file mode 100644 index 00000000..5a5b2a10 --- /dev/null +++ b/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/rest/FescarRestTemplateInterceptor.java @@ -0,0 +1,46 @@ +/* + * Copyright (C) 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 + * + * 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, + * 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 org.springframework.cloud.alibaba.fescar.rest; + +import java.io.IOException; + +import com.alibaba.fescar.core.context.RootContext; + +import org.springframework.http.HttpRequest; +import org.springframework.http.client.ClientHttpRequestExecution; +import org.springframework.http.client.ClientHttpRequestInterceptor; +import org.springframework.http.client.ClientHttpResponse; +import org.springframework.http.client.support.HttpRequestWrapper; +import org.springframework.util.StringUtils; + +/** + * @author xiaojing + */ +public class FescarRestTemplateInterceptor implements ClientHttpRequestInterceptor { + @Override + public ClientHttpResponse intercept(HttpRequest httpRequest, byte[] bytes, + ClientHttpRequestExecution clientHttpRequestExecution) throws IOException { + HttpRequestWrapper requestWrapper = new HttpRequestWrapper(httpRequest); + + String xid = RootContext.getXID(); + + if (!StringUtils.isEmpty(xid)) { + requestWrapper.getHeaders().add(RootContext.KEY_XID, xid); + } + return clientHttpRequestExecution.execute(requestWrapper, bytes); + } +} diff --git a/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/web/FescarHandlerInterceptor.java b/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/web/FescarHandlerInterceptor.java new file mode 100644 index 00000000..50883c4e --- /dev/null +++ b/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/web/FescarHandlerInterceptor.java @@ -0,0 +1,93 @@ +/* + * Copyright (C) 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 + * + * 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, + * 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 org.springframework.cloud.alibaba.fescar.web; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.alibaba.fescar.core.context.RootContext; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.util.StringUtils; +import org.springframework.web.servlet.HandlerInterceptor; +import org.springframework.web.servlet.ModelAndView; + +/** + * @author xiaojing + * + * Fescar HandlerInterceptor, Convert Fescar information into + * @see com.alibaba.fescar.core.context.RootContext from http request's header in + * {@link org.springframework.web.servlet.HandlerInterceptor#preHandle(HttpServletRequest , HttpServletResponse , Object )}, + * And clean up Fescar information after servlet method invocation in + * {@link org.springframework.web.servlet.HandlerInterceptor#afterCompletion(HttpServletRequest, HttpServletResponse, Object, Exception)} + */ +public class FescarHandlerInterceptor implements HandlerInterceptor { + + private static final Logger log = LoggerFactory + .getLogger(FescarHandlerInterceptor.class); + + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, + Object handler) throws Exception { + + String xid = RootContext.getXID(); + String rpcXid = request.getHeader(RootContext.KEY_XID); + if (log.isDebugEnabled()) { + log.debug("xid in RootContext {} xid in RpcContext {}", xid, rpcXid); + } + + if (xid == null && rpcXid != null) { + RootContext.bind(rpcXid); + if (log.isDebugEnabled()) { + log.debug("bind {} to RootContext", rpcXid); + } + } + return true; + } + + @Override + public void postHandle(HttpServletRequest httpServletRequest, + HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) + throws Exception { + + } + + @Override + public void afterCompletion(HttpServletRequest request, HttpServletResponse response, + Object handler, Exception e) throws Exception { + + String rpcXid = request.getHeader(RootContext.KEY_XID); + + if (StringUtils.isEmpty(rpcXid)) { + return; + } + + String unbindXid = RootContext.unbind(); + if (log.isDebugEnabled()) { + log.debug("unbind {} from RootContext", unbindXid); + } + if (!rpcXid.equalsIgnoreCase(unbindXid)) { + log.warn("xid in change during RPC from {} to {}", rpcXid, unbindXid); + if (unbindXid != null) { + RootContext.bind(unbindXid); + log.warn("bind {} back to RootContext", unbindXid); + } + } + } + +} diff --git a/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/web/FescarHandlerInterceptorConfiguration.java b/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/web/FescarHandlerInterceptorConfiguration.java new file mode 100644 index 00000000..d6b94acc --- /dev/null +++ b/spring-cloud-alibaba-fescar/src/main/java/org/springframework/cloud/alibaba/fescar/web/FescarHandlerInterceptorConfiguration.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 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 + * + * 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, + * 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 org.springframework.cloud.alibaba.fescar.web; + +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; + +/** + * @author xiaojing + */ +public class FescarHandlerInterceptorConfiguration extends WebMvcConfigurerAdapter { + + @Override + public void addInterceptors(InterceptorRegistry registry) { + registry.addInterceptor(new FescarHandlerInterceptor()).addPathPatterns("/**"); + super.addInterceptors(registry); + } +} diff --git a/spring-cloud-alibaba-fescar/src/main/resources/META-INF/spring.factories b/spring-cloud-alibaba-fescar/src/main/resources/META-INF/spring.factories new file mode 100644 index 00000000..3560bcee --- /dev/null +++ b/spring-cloud-alibaba-fescar/src/main/resources/META-INF/spring.factories @@ -0,0 +1,7 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ +org.springframework.cloud.alibaba.fescar.rest.FescarRestTemplateAutoConfiguration,\ +org.springframework.cloud.alibaba.fescar.web.FescarHandlerInterceptorConfiguration,\ +org.springframework.cloud.alibaba.fescar.GlobalTransactionAutoConfiguration,\ +org.springframework.cloud.alibaba.fescar.feign.FescarFeignClientAutoConfiguration,\ +org.springframework.cloud.alibaba.fescar.feign.hystrix.FescarHystrixAutoConfiguration + diff --git a/spring-cloud-starter-alibaba/pom.xml b/spring-cloud-starter-alibaba/pom.xml index 3d3f8e81..36b815cb 100644 --- a/spring-cloud-starter-alibaba/pom.xml +++ b/spring-cloud-starter-alibaba/pom.xml @@ -17,6 +17,7 @@ spring-cloud-starter-alibaba-nacos-config spring-cloud-starter-alibaba-nacos-discovery spring-cloud-starter-alibaba-sentinel + spring-cloud-starter-alibaba-fescar spring-cloud-starter-stream-rocketmq spring-cloud-starter-bus-rocketmq diff --git a/spring-cloud-starter-alibaba/spring-cloud-starter-alibaba-fescar/pom.xml b/spring-cloud-starter-alibaba/spring-cloud-starter-alibaba-fescar/pom.xml new file mode 100644 index 00000000..46441606 --- /dev/null +++ b/spring-cloud-starter-alibaba/spring-cloud-starter-alibaba-fescar/pom.xml @@ -0,0 +1,20 @@ + + 4.0.0 + + + org.springframework.cloud + spring-cloud-starter-alibaba + 0.1.2.BUILD-SNAPSHOT + + spring-cloud-starter-alibaba-fescar + Spring Cloud Starter Alibaba Fescar + + + + org.springframework.cloud + spring-cloud-alibaba-fescar + + + +