Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
CAP
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
CAP
Commits
cfc12aa9
Commit
cfc12aa9
authored
Jul 10, 2017
by
AlexLEWIS
Committed by
GitHub
Jul 10, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update README.zh-cn.md
parent
1e0b8461
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
22 deletions
+26
-22
README.zh-cn.md
README.zh-cn.md
+26
-22
No files found.
README.zh-cn.md
View file @
cfc12aa9
# CAP [English](https://github.com/dotnetcore/CAP/blob/master/README.md)
<p
align=
"right"
>
<a
href=
"https://github.com/dotnetcore/CAP/blob/master/README.md"
>
English
</a>
</p>
# CAP
[

](https://travis-ci.org/dotnetcore/CAP)
[

](https://ci.appveyor.com/project/yuleyule66/cap)
[

](https://www.nuget.org/packages/DotNetCore.CAP/)
[

](https://raw.githubusercontent.com/dotnetcore/CAP/master/LICENSE.txt)
CAP
是一个在分布式系统(SOA、MicroService)中实现最终一致性的库,它具有轻量级、易使用、高性能等特点。
CAP
是一个在分布式系统(SOA、MicroService)中实现最终一致性的库,它具有轻量级、易使用、高性能等特点。
##
预览(OverView)
##
预览(OverView)
CAP
是在一个 ASP.NET Core 项目中使用的库,当然他可以用于 ASP.NET Core On .NET Framework 中。
CAP
是在一个 ASP.NET Core 项目中使用的库,当然他可以用于 ASP.NET Core On .NET Framework 中。
你可以把 CAP 看成是一个 EventBus,因为它具有 EventBus 的所有功能,并且 CAP 提供了更加简化的方式来处理 EventBus 中的发布和订阅。
你可以把 CAP 看成是一个 EventBus,因为它具有 EventBus 的所有功能,并且 CAP 提供了更加简化的方式来处理 EventBus 中的发布和订阅。
CAP
具有消息持久化的功能,当你的服务进行重启或者宕机时它可以保证消息的可靠性。CAP提供了基于Microsoft DI 的 Publisher Service 服务,它可以和你的业务服务进行无缝结合,并且支持强一致性的事务。
CAP
具有消息持久化的功能,当你的服务进行重启或者宕机时它可以保证消息的可靠性。CAP提供了基于Microsoft DI 的 Publisher Service 服务,它可以和你的业务服务进行无缝结合,并且支持强一致性的事务。
这是CAP集在ASP.NET Core 微服务架构中的一个示意图:
这是CAP集在ASP.NET Core 微服务架构中的一个示意图:

>
图中实线部分代表用户代码,虚线部分代表CAP内部实现。
>
图中实线部分代表用户代码,虚线部分代表CAP内部实现。
## Getting Started
### NuGet
你可以运行以下下命令在你的项目中安装 CAP。
你可以运行以下下命令在你的项目中安装 CAP。
如果你的消息队列使用的是 Kafka 的话,你可以:
如果你的消息队列使用的是 Kafka 的话,你可以:
```
PM> Install-Package DotNetCore.CAP.Kafka -Pre
```
如果你的消息队列使用的是 RabbitMQ 的话,你可以:
如果你的消息队列使用的是 RabbitMQ 的话,你可以:
```
PM> Install-Package DotNetCore.CAP.RabbitMQ -Pre
```
CAP
默认提供了 Entity Framwork 作为数据库存储:
CAP
默认提供了 Entity Framwork 作为数据库存储:
```
PM> Install-Package DotNetCore.CAP.EntityFrameworkCore -Pre
...
...
@@ -46,7 +50,7 @@ PM> Install-Package DotNetCore.CAP.EntityFrameworkCore -Pre
### Configuration
首先配置CAP到 Startup.cs 文件中,如下:
首先配置CAP到 Startup.cs 文件中,如下:
```
cs
public
void
ConfigureServices
(
IServiceCollection
services
)
...
...
@@ -69,9 +73,9 @@ public void Configure(IApplicationBuilder app)
```
###
发布
###
发布
在 Controller 中注入
`ICapPublisher`
然后使用
`ICapPublisher`
进行消息发送
在 Controller 中注入
`ICapPublisher`
然后使用
`ICapPublisher`
进行消息发送
```
cs
public
class
PublishController
:
Controller
...
...
@@ -87,7 +91,7 @@ public class PublishController : Controller
[
Route
(
"~/checkAccount"
)]
public
async
Task
<
IActionResult
>
PublishMessage
()
{
//
指定发送的消息头和内容
//
指定发送的消息头和内容
await
_publisher
.
PublishAsync
(
"xxx.services.account.check"
,
new
Person
{
Name
=
"Foo"
,
Age
=
11
});
return
Ok
();
...
...
@@ -96,11 +100,11 @@ public class PublishController : Controller
```
###
订阅
###
订阅
**Action Method**
在 Action 上添加 CapSubscribeAttribute 来订阅相关消息。
在 Action 上添加 CapSubscribeAttribute 来订阅相关消息。
```
cs
public
class
PublishController
:
Controller
...
...
@@ -127,7 +131,7 @@ public class PublishController : Controller
**Service Method**
如果你的订阅方法没有位于 Controller 中,则你订阅的类需要继承
`ICapSubscribe`
:
如果你的订阅方法没有位于 Controller 中,则你订阅的类需要继承
`ICapSubscribe`
:
```
cs
...
...
@@ -151,7 +155,7 @@ namespace xxx.Service
```
然后在 Startup.cs 中的
`ConfigureServices()`
中注入你的
`ISubscriberService`
类
然后在 Startup.cs 中的
`ConfigureServices()`
中注入你的
`ISubscriberService`
类
```
cs
public
void
ConfigureServices
(
IServiceCollection
services
)
...
...
@@ -160,9 +164,9 @@ public void ConfigureServices(IServiceCollection services)
}
```
##
贡献
##
贡献
贡献的最简单的方法之一就是是参与讨论和讨论问题(issue)。你也可以通过提交的 Pull Request 代码变更作出贡献。
贡献的最简单的方法之一就是是参与讨论和讨论问题(issue)。你也可以通过提交的 Pull Request 代码变更作出贡献。
### License
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment