Skip to content

Commit

Permalink
cola 4.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
fulan.zjf committed Dec 9, 2020
1 parent 9d1aa68 commit 91126a6
Show file tree
Hide file tree
Showing 255 changed files with 1,032 additions and 4,904 deletions.
145 changes: 62 additions & 83 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,111 +1,74 @@
# COLA 3.0架构
<strong>COLA是Clean Object-Oriented and Layered Architecture的缩写,表示“整洁面向对象分层架构”,目前COLA已经发展到[COLA 3.0](https://blog.csdn.net/significantfrank/article/details/106976804)。</strong> 需要访问老版本,请使用[COLA 2.0 TAG](https://github.com/alibaba/COLA/tree/COLA2.0), [COLA 1.0 TAG](https://github.com/alibaba/COLA/tree/COLA1.0)
# COLA 4.0
<strong>COLA是Clean Object-Oriented and Layered Architecture的缩写,代表“整洁面向对象分层架构”,目前COLA已经发展到[COLA 4.0](https://blog.csdn.net/significantfrank/article/details/110934799)。</strong>

关于COLA的更多信息,请关注微信公众号:

![qrcode_60.jpg](https://img-blog.csdnimg.cn/2020110314110321.png#pic_center)

如果你有技术热情,对阿里有兴趣,可以email:fulan.zjf@alibaba-inc.com

# 阿里云COLA应用生成器
https://start.aliyun.com/bootstrap.html
![image.png](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9hdGEyLWltZy5vc3MtY24temhhbmdqaWFrb3UuYWxpeXVuY3MuY29tLzQ4Zjg3MGI5OGQ2Y2VhN2YwNjg2NGUxNzM4N2UwNzE3LnBuZw?x-oss-process=image/format,png)
COLA分为两个部分,COLA架构和COLA组件。

# 项目说明
**COLA既是框架,也是架构。创建COLA的主要目的是为应用架构提供一套简单的可以复制、可以理解、可以落地、可以控制复杂性的”指导和约束"。**
- 架构部分主要是提供了创建符合COLA要求的应用Archetype
- 框架部分主要是以二方库的形式被应用依赖和使用。
# COLA架构
架构的意义就是要素结构,要素是组成架构的重要元素,结构是要素之间的关系。应用架构的意义就在于定义一套良好的结构,治理应用复杂度,
降低系统熵值,从随心所欲的混乱状态,走向紧紧有条的有序状态
![archWhy](https://img-blog.csdnimg.cn/20201209182220206.png)

## COLA架构
COLA首先是作为架构的存在,是一种应用架构思想,主要是制定了一套指导和约束,并将这套规范沉淀成Archetype。以便通过Archetype可以快速的生成符合COLA规范的应用。满足COLA的应用是一个有清晰的依赖关系的分层架构,如下图所示:
COLA架构就是为此而生,其核心职责就是定义良好的应用结构,提供最佳应用架构的最佳实践。
通过不断探索,我们发现良好的分层结构,良好的包结构定义,可以帮助我们治理混乱不堪的业务应用系统。
![cure](https://img-blog.csdnimg.cn/2020120918285068.png)

![COLA3.1](https://img-blog.csdnimg.cn/20201106130015912.png#pic_center)
经过多次迭代,我们定义出了相对稳定、可靠的应用架构:COLA 4.0
![cola](https://img-blog.csdnimg.cn/20201209182934838.png)

我们提供了两个Archetype,分别是cola-archetype-service和cola-archetype-web
# COLA Archetype
好的应用架构,都遵循一些共同模式,不管是六边形架构、洋葱圈架构、整洁架构、还是COLA架构,**都提倡以业务为核心,解耦外部依赖,分离业务复杂度和技术复杂度等**

### cola-archetype-service
用来生成纯后端应用(没有Adapter),生成应用的命令为:
```
mvn archetype:generate -DgroupId=com.alibaba.demo -DartifactId=demoService -Dversion=1.0.0-SNAPSHOT -Dpackage=com.alibaba.demo -DarchetypeArtifactId=cola-framework-archetype-service -DarchetypeGroupId=com.aliyun -DarchetypeVersion=3.1.0
```
COLA架构区别于这些架构的地方,在于除了思想之外,我们还提供了可落地的工具和实践指导。

### cola-archetype-web
用来生成Web后端应用(有Adapter),生成应用的命令为:
```
mvn archetype:generate -DgroupId=com.alibaba.demo -DartifactId=demoWeb -Dversion=1.0.0-SNAPSHOT -Dpackage=com.alibaba.demo -DarchetypeArtifactId=cola-framework-archetype-web -DarchetypeGroupId=com.aliyun -DarchetypeVersion=3.1.0
```
为了能够快速创建满足COLA架构的应用,我们提供了两个Archetype,他们在cola-archetypes下面。

## COLA框架
其次,COLA也是一个框架,提供了扩展点功能组件和一般API定义规范组件。如果你打算使用COLA提供的扩展点功能。
你需要在项目里面依赖两个组件:[cola-core](https://oss.sonatype.org/#nexus-search;quick~cola-core), [cola-common](https://oss.sonatype.org/#nexus-search;quick~cola-common)
1. 一个是用来创建纯后端服务的archetype:cola-archetype-service。
2. 一个是用来创建adapter和后端服务一体的web应用archetype:cola-archetype-web。

关于组件引用方式,你可以下载源码在本地生成,也可以从nexus的中央仓库获取。下面简单介绍一下这两个组件:
# COLA Components
此外,我们还提供了一些非常有用的通用组件,这些组件可以帮助我们提升研发效率。

### cola-framework-core
该Module是整个框架的核心,里面的主要功能和Package如下:
```
com
└── alibaba
└── cola
├── boot \\这是框架的核心启动包,负责框架组件的注册、发现
├── common
├── domain \\提供Domain Entity标准
├── exception \\提供Exception标准
├── extension \\负责扩展机制中的重要概念-扩展(Extension)的定义和执行
├── logger \\提供DIP的日志接口
```
### cola-framework-common
该Module提供了应用中通用DTO, Exception的定义,二方库会依赖该Module。
这些功能组件被收拢在cola-components下面。到目前为止,我们已经沉淀了以下组件:

组件名称 | 功能 | 版本 | 依赖
---|---|---|---
cola-component-dto | 定义了DTO格式,包括分页 | 1.0.0 |无
cola-component-exception | 定义了异常格式,<br>主要有BizException和SysException | 1.0.0 |无
cola-component-dto | 定义了DTO格式,包括分页 | 1.0.0 |无
cola-component-statemachine | 状态机组件 | 1.0.0 |无
cola-component-domain-starter | Spring托管的领域实体组件 | 1.0.0 |无
cola-component-catchlog-starter | 异常处理和日志组件 | 1.0.0 |exception<br>,dto组件
cola-component-extension-starter| 扩展点组件 | 1.0.0 |无
cola-component-test-container| 测试容器组件 | 1.0.0 |无

# 如何使用COLA

## 第一步:生成COLA应用
**1、使用Archetype生成应用:**
## 第一步:安装 cola archetype
下载cola-archetypes下的源码到本地,然后本地运行mvn install安装。

直接运行上面提供的Archetype命令就可以生成应用,默认,你可以在中央仓库获取到[cola-archetype-service](https://oss.sonatype.org/#nexus-search;quick~cola-framework-archetype-service)[cola-archetype-web](https://oss.sonatype.org/#nexus-search;quick~cola-framework-archetype-web)
## 第二步:安装 cola components
下载cola-components下的源码到本地,然后本地运行mvn install安装。

如果downloading有问题,也可以自己下载Archetype源码到本地,然后本地运行mvn install安装。

**2、 检查应用里的模块和组件:**

如果命令执行成功的话,我们可以看到如下的代码结构:

![ComponentDiag](https://img-blog.csdnimg.cn/20201106134114574.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3NpZ25pZmljYW50ZnJhbms=,size_16,color_FFFFFF,t_70#pic_center)

## 第二步:运行Demo
**1、进入在第一步中生成的应用目录。**
## 第三步:创建应用
执行以下命令:
```
mvn archetype:generate -DgroupId=com.alibaba.demo -DartifactId=demoWeb -Dversion=1.0.0-SNAPSHOT -Dpackage=com.alibaba.demo -DarchetypeArtifactId=cola-framework-archetype-web -DarchetypeGroupId=com.alibaba.cola -DarchetypeVersion=4.0.0
```
命令执行成功的话,会看到如下的应用代码结构:
![demo](https://img-blog.csdnimg.cn/20201209192258840.png)

**2、启动SpringBoot:**
注:也可以使用阿里云的应用生成器:https://start.aliyun.com/bootstrap.html 生成cola应用。

## 第四步:运行应用
首先在demoWeb目录下运行mvn install(如果不想运行测试,可以加上-DskipTests参数)。然后进入start目录,执行mvn spring-boot:run
运行成功的话,可以看到SpringBoot启动成功的界面。

**3、 执行测试:**

生成的应用中,已经实现了一个简单的Rest请求,可以在浏览器中输入 http://localhost:8080/helloworld 进行测试。

**4、查看运行日志:**

请求执行成功的话,可以在浏览器中的返回值中看到:"Hello, welcome to cola world"。


# 版本迭代
## 1.0.0 版本
https://blog.csdn.net/significantfrank/article/details/85785565

## 2.0.0 版本
https://blog.csdn.net/significantfrank/article/details/100074716

## 3.0.0 版本
https://blog.csdn.net/significantfrank/article/details/106976804

## 3.0.1 版本
之前的扩展点在locate扩展实现的时候,没有寻找默认实现的能力。增强之后,可以去寻找默认实现了。
比如,"tmall.placeOrder.88vip"这个场景,其寻找扩展点的路径是:
1. 尝试寻找"tmall.placeOrder.88vip"实现
2. 如果没有,继续寻找"tmall.placeOrder"实现
3. 如果没有,继续寻找"tmall"实现
## 4.0.0 版本
https://blog.csdn.net/significantfrank/article/details/110934799

## 3.1.0 版本
https://blog.csdn.net/significantfrank/article/details/109529311
Expand All @@ -114,3 +77,19 @@ https://blog.csdn.net/significantfrank/article/details/109529311
3. 对archetype中的分包逻辑进行重构,改成按照domain做划分。
4. 将cola-archetype-web中的controller改名为adapter,为了呼应六边形架构的命名。

## 3.0.0 版本
https://blog.csdn.net/significantfrank/article/details/106976804

## 2.0.0 版本
https://blog.csdn.net/significantfrank/article/details/100074716

## 1.0.0 版本
https://blog.csdn.net/significantfrank/article/details/85785565


关于COLA的更多信息,请关注微信公众号:
![qrcode_60.jpg](https://img-blog.csdnimg.cn/2020110314110321.png#pic_center)

如果你有技术热情,对阿里有兴趣,可以email:fulan.zjf@alibaba-inc.com


This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.aliyun</groupId>
<groupId>com.alibaba.cola</groupId>
<artifactId>cola-framework-archetype-service</artifactId>
<version>3.1.0</version>
<version>4.0.0</version>
<packaging>jar</packaging>

<name>cola framework archetype</name>
<name>cola-archetype-service</name>
<url>https://github.com/alibaba/COLA</url>
<description>Cola framework archetype-service</description>

Expand Down Expand Up @@ -100,7 +100,7 @@
<doclint>none</doclint>
</configuration>
</plugin>
<!-- This is for central repository, comment it when build at local-->
<!-- This is for central repository, comment it when build at local
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
Expand All @@ -115,7 +115,7 @@
</execution>
</executions>
</plugin>

-->
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
<groupId>${groupId}</groupId>
<artifactId>${rootArtifactId}-infrastructure</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cola</groupId>
<artifactId>cola-component-catchlog-starter</artifactId>
</dependency>
<!-- JSR 303 Validation -->
<dependency>
<groupId>org.hibernate.validator</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import com.alibaba.cola.dto.MultiResponse;
import com.alibaba.cola.dto.Response;
import com.alibaba.cola.catchlog.CatchAndLog;
import ${package}.api.CustomerServiceI;
import ${package}.dto.CustomerAddCmd;
import ${package}.dto.CustomerListByNameQry;
Expand All @@ -17,8 +18,8 @@

import javax.annotation.Resource;


@Service
@CatchAndLog
public class CustomerServiceImpl implements CustomerServiceI {

@Resource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ public MultiResponse<CustomerDTO> execute(CustomerListByNameQry cmd) {
CustomerDTO customerDTO = new CustomerDTO();
customerDTO.setCustomerName("Frank");
customerDTOList.add(customerDTO);
return MultiResponse.ofWithoutTotal(customerDTOList);
return MultiResponse.of(customerDTOList);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<name>${parentArtifactId}-client</name>
<dependencies>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>cola-common</artifactId>
<groupId>com.alibaba.cola</groupId>
<artifactId>cola-component-dto</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
Expand Down
Loading

0 comments on commit 91126a6

Please sign in to comment.