|
|
|
@ -24,82 +24,15 @@ ABP框架的主要目标之一就是提供[便捷的基础设施来创建微服 |
|
|
|
|
|
|
|
下图展示了该系统: |
|
|
|
|
|
|
|
 |
|
|
|
 |
|
|
|
|
|
|
|
### 源码 |
|
|
|
|
|
|
|
你可以从[GitHub仓库](https://github.com/abpframework/abp/tree/master/samples/MicroserviceDemo)获取源码. |
|
|
|
|
|
|
|
### 状态 |
|
|
|
|
|
|
|
该示例的初始版本已完成.其他改进仍在开发中. |
|
|
|
|
|
|
|
## 运行解决方案 |
|
|
|
|
|
|
|
您可以从 **源代码** 或者预先配置好的 **docker-compose** 文件运行. |
|
|
|
|
|
|
|
### 使用Docker容器 |
|
|
|
|
|
|
|
#### 预先要求 |
|
|
|
|
|
|
|
由于所有依赖项都已预先配置, 因此作为Docker容器运行更容易. 你只需要安装[最新的docker](https://docs.docker.com/compose/install/). |
|
|
|
|
|
|
|
#### 运行容器 |
|
|
|
|
|
|
|
- 克隆或下载 [ABP仓库](https://github.com/abpframework/abp). |
|
|
|
|
|
|
|
- 在存储库的`samples/MicroserviceDemo`文件夹中打开命令行. |
|
|
|
|
|
|
|
- 从Docker Hub中拉取image: |
|
|
|
|
|
|
|
``` |
|
|
|
docker-compose -f docker-compose.yml -f docker-compose.migrations.yml pull |
|
|
|
``` |
|
|
|
|
|
|
|
- 如果要在本地构建映像, 可以跳过上述步骤, 使用build命令: |
|
|
|
|
|
|
|
``` |
|
|
|
docker-compose -f docker-compose.yml -f docker-compose.migrations.yml build |
|
|
|
``` |
|
|
|
|
|
|
|
根据你的电脑配置, 构建image可能需要**很长时间**. |
|
|
|
|
|
|
|
- 还原 SQL Server 数据库: |
|
|
|
|
|
|
|
``` |
|
|
|
docker-compose -f docker-compose.yml -f docker-compose.migrations.yml run restore-database |
|
|
|
``` |
|
|
|
|
|
|
|
- 启动容器: |
|
|
|
|
|
|
|
``` |
|
|
|
docker-compose up -d |
|
|
|
``` |
|
|
|
|
|
|
|
- 将此行添加到`hosts`文件的末尾: |
|
|
|
|
|
|
|
``` |
|
|
|
127.0.0.1 auth-server |
|
|
|
``` |
|
|
|
|
|
|
|
hosts文件位于Windows上的`C:\Windows\System32\Drivers\etc\hosts`文件夹, Linux/MacOS的`/etc/hosts`中. |
|
|
|
|
|
|
|
#### 运行应用程序 |
|
|
|
|
|
|
|
你可能想要了解容器中运行一些应用程序: |
|
|
|
|
|
|
|
* 后端管理应用程序 (BackendAdminApp.Host): `http://localhost:51512` |
|
|
|
*(用于管理系统中的用户和产品)* |
|
|
|
* 公共网站 (PublicWebsite.Host): `http://localhost:51513` |
|
|
|
*(用于列出产品并运行/管理博客模块)* |
|
|
|
* 认证服务器 (AuthServer.Host): `http://auth-server:51511/` |
|
|
|
*(用作使用IdentityServer4构建的单点登录和身份验证服务器)* |
|
|
|
* Kibana UI: `http://localhost:51510` |
|
|
|
*(用于显示/跟踪所有服务/应用程序/网关写入的日志)* |
|
|
|
|
|
|
|
### 从源代码运行 |
|
|
|
|
|
|
|
#### 预先要求 |
|
|
|
### 预先要求 |
|
|
|
|
|
|
|
为了能够从源代码运行解决方案, 应在你的计算机上安装并运行以下工具: |
|
|
|
|
|
|
|
@ -110,19 +43,19 @@ ABP框架的主要目标之一就是提供[便捷的基础设施来创建微服 |
|
|
|
* [ElasticSearch](https://www.elastic.co/downloads/elasticsearch) 6.6+ |
|
|
|
* [Kibana](https://www.elastic.co/downloads/kibana) 6.6+ (可选,建议显示日志) |
|
|
|
|
|
|
|
#### 打开并构建Visual Studio解决方案 |
|
|
|
### 打开并构建Visual Studio解决方案 |
|
|
|
|
|
|
|
* 在Visual Studio 2017 (15.9.0+)中打开`samples\MicroserviceDemo\MicroserviceDemo.sln`. |
|
|
|
* 在`samples\MicroserviceDemo`文件夹中的命令行运行`dotnet restore`命令. |
|
|
|
* 在Visual Studio中构建解决方案. |
|
|
|
|
|
|
|
#### 创建数据库 |
|
|
|
### 创建数据库 |
|
|
|
|
|
|
|
MongoDB 数据库是动态创建的,但是你需要创建 SQL server 数据库的结构。其实你可以很轻松的创建数据库,因为这个解决方案配置了使用 Entity Core Code First 来做迁移。 |
|
|
|
|
|
|
|
这个解决方案中有两个 SQL server 数据库。 |
|
|
|
|
|
|
|
##### MsDemo_Identity 数据库 |
|
|
|
#### MsDemo_Identity 数据库 |
|
|
|
|
|
|
|
* 右键 `AuthServer.Host` 项目,然后点击 `设置为启动项目`. |
|
|
|
* 打开 **程序包管理器控制台** (工具 -> NuGet 包管理器 -> 程序包管理器控制台) |
|
|
|
@ -131,7 +64,7 @@ MongoDB 数据库是动态创建的,但是你需要创建 SQL server 数据库 |
|
|
|
|
|
|
|
 |
|
|
|
|
|
|
|
##### MsDemo_ProductManagement |
|
|
|
#### MsDemo_ProductManagement |
|
|
|
|
|
|
|
* 右键 `ProductService.Host` 项目,然后点击 `设置为启动项目`. |
|
|
|
* 打开 **程序包管理器控制台** (工具 -> NuGet 包管理器 -> 程序包管理器控制台) |
|
|
|
@ -140,12 +73,13 @@ MongoDB 数据库是动态创建的,但是你需要创建 SQL server 数据库 |
|
|
|
|
|
|
|
 |
|
|
|
|
|
|
|
#### 运行项目 |
|
|
|
### 运行项目 |
|
|
|
|
|
|
|
按以下顺序运行项目(右键单击每个项目设置为启动项目,按Ctrl+F5运行,无需调试): |
|
|
|
|
|
|
|
* AuthServer.Host |
|
|
|
* IdentityService.Host |
|
|
|
* TenantManagementService.Host |
|
|
|
* BloggingService.Host |
|
|
|
* ProductService.Host |
|
|
|
* InternalGateway.Host |
|
|
|
@ -158,7 +92,7 @@ MongoDB 数据库是动态创建的,但是你需要创建 SQL server 数据库 |
|
|
|
|
|
|
|
Visual Studio解决方案由多个项目组成,每个项目在系统中具有不同的角色: |
|
|
|
|
|
|
|
 |
|
|
|
 |
|
|
|
|
|
|
|
### 应用程序(Applications) |
|
|
|
|
|
|
|
@ -182,6 +116,7 @@ Visual Studio解决方案由多个项目组成,每个项目在系统中具有不 |
|
|
|
微服务没有UI,但暴露了一些REST API. |
|
|
|
|
|
|
|
- **IdentityService.Host**: 托管用于管理用户和角色的ABP Identity模块. 它没有其他服务,仅托管Identity模块的API. |
|
|
|
- **TenantManagementService.Host**: 托管用于管理角色的ABP租户管理模块. 它没有其他服务,仅托管租户管理模块的API. |
|
|
|
- **BloggingService.Host**: 托管ABP博客模块,该模块用于管理博客和帖子(典型的博客应用程序). 它没有其他服务,仅托管Blogging模块的API. |
|
|
|
- **ProductService.Host**: 托管用于管理产品的产品模块(位于解决方案内). 它还包含用于创建/更新产品管理数据库架构的EF Core迁移. |
|
|
|
|
|
|
|
@ -193,7 +128,7 @@ Visual Studio解决方案由多个项目组成,每个项目在系统中具有不 |
|
|
|
|
|
|
|
此解决方案使用多个数据库: |
|
|
|
|
|
|
|
* **MsDemo_Identity**: 一个SQL数据库. 默认使用**SQL Server**,但可以是EF Core支持的任何DBMS. 由AuthServer和IdentityService共享. 审计日志,权限和设置也存储在此数据库中(虽然它们可以轻松拥有自己的数据库,共享相同的数据库以保持简单). |
|
|
|
* **MsDemo_Identity**: 一个SQL数据库. 默认使用**SQL Server**,但可以是EF Core支持的任何DBMS. 由AuthServer,IdentityService和TenantManagementService共享. 审计日志,权限和设置也存储在此数据库中(虽然它们可以轻松拥有自己的数据库,共享相同的数据库以保持简单). |
|
|
|
* **MsDemo_ProductManagement**: 一个SQL数据库. 同样默认使用 **SQL Server**,但可以是EF Core支持的任何DBMS. 由ProductService用作专用数据库. |
|
|
|
* **MsDemo_Blogging**: **MongoDB**数据库. 由BloggingService使用. |
|
|
|
* **Elasticsearch**: 用于在Serilog上写日志. |
|
|
|
@ -1474,3 +1409,7 @@ ABP提供自动审计日志记录,详细保存每个请求(当前用户,浏览 |
|
|
|
所有服务和应用程序都配置为编写审核日志. 审核日志将保存到MsDemo_Identity SQL数据库中. 因此,您可以从单个点查询所有应用程序的所有审核日志. |
|
|
|
|
|
|
|
审核日志记录具有`CorrelationId`属性,可用于跟踪请求. 当服务在单个Web请求中调用另一个服务时,它们都会使用相同的`CorrelationId`保存审核日志. 请参阅数据库中的`AbpAuditLogs`表. |
|
|
|
|
|
|
|
### 多租户 |
|
|
|
|
|
|
|
该解决方案已配置提供[多租户](../Multi-Tenancy.md)系统,其中每个租户可以拥有其隔离的用户,角色,权限和其他数据. |