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
e7fe6e7f
Commit
e7fe6e7f
authored
Jul 19, 2017
by
yangxiaodong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update guide with new api.
parent
0f573d5e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
6 deletions
+35
-6
README.zh-cn.md
README.zh-cn.md
+35
-6
No files found.
README.zh-cn.md
View file @
e7fe6e7f
...
...
@@ -6,6 +6,7 @@
[

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

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

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

](https://github.com/dotnetcore)
[

](https://raw.githubusercontent.com/dotnetcore/CAP/master/LICENSE.txt)
CAP 是一个在分布式系统(SOA、MicroService)中实现最终一致性的库,它具有轻量级、易使用、高性能等特点。
...
...
@@ -30,6 +31,10 @@ CAP 具有消息持久化的功能,当你的服务进行重启或者宕机时
你可以运行以下下命令在你的项目中安装 CAP。
```
PM> Install-Package DotNetCore.CAP -Pre
```
如果你的消息队列使用的是 Kafka 的话,你可以:
```
...
...
@@ -42,10 +47,10 @@ PM> Install-Package DotNetCore.CAP.Kafka -Pre
PM> Install-Package DotNetCore.CAP.RabbitMQ -Pre
```
CAP 默认提供了
Entity Framwork 作为数据库存储
:
CAP 默认提供了
Sql Server 的扩展作为数据库存储(MySql的正在开发中)
:
```
PM> Install-Package DotNetCore.CAP.
EntityFrameworkCore
-Pre
PM> Install-Package DotNetCore.CAP.
SqlServer
-Pre
```
### Configuration
...
...
@@ -57,11 +62,23 @@ public void ConfigureServices(IServiceCollection services)
{
......
services
.
AddDbContext
<
AppDbContext
>();
services
.
AddDbContext
<
AppDbContext
>();
services
.
AddCap
()
.
AddEntityFrameworkStores
<
AppDbContext
>()
.
AddKafka
(
x
=>
x
.
Servers
=
"localhost:9092"
);
services
.
AddCap
(
x
=>
{
// 如果你的 SqlServer 使用的 EF 进行数据操作,你需要添加如下配置:
// 注意: 你不需要再次配置 x.UseSqlServer(""")
x
.
UseEntityFramework
<
AppDbContext
>();
// 如果你使用的Dapper,你需要添加如下配置:
x
.
UseSqlServer
(
"数据库连接字符串"
);
// 如果你使用的 RabbitMQ 作为MQ,你需要添加如下配置:
x
.
UseRabbitMQ
(
"localhost"
);
//如果你使用的 Kafka 作为MQ,你需要添加如下配置:
x
.
UseKafka
(
"localhost"
);
});
}
public
void
Configure
(
IApplicationBuilder
app
)
...
...
@@ -96,6 +113,18 @@ public class PublishController : Controller
return
Ok
();
}
[
Route
(
"~/checkAccountWithTrans"
)]
public
async
Task
<
IActionResult
>
PublishMessageWithTransaction
([
FromServices
]
AppDbContext
dbContext
)
{
using
(
var
trans
=
dbContext
.
Database
.
BeginTransaction
())
{
await
_publisher
.
PublishAsync
(
"xxx.services.account.check"
,
new
Person
{
Name
=
"Foo"
,
Age
=
11
});
trans
.
Commit
();
}
return
Ok
();
}
}
```
...
...
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