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
ae671216
Commit
ae671216
authored
Oct 31, 2017
by
Savorboard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update readme
parent
d97f1f7f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
20 deletions
+46
-20
README.md
README.md
+23
-10
README.zh-cn.md
README.zh-cn.md
+23
-10
No files found.
README.md
View file @
ae671216
...
...
@@ -99,27 +99,40 @@ Inject `ICapPublisher` in your Controller, then use the `ICapPublisher` to send
```
c#
public
class
PublishController
:
Controller
{
private
readonly
AppDbContext
_dbContext
;
public
PublishController
(
AppDbContext
dbContext
)
{
_dbContext
=
dbContext
;
}
[
Route
(
"~/checkAccountWithTrans"
)]
public
async
Task
<
IActionResult
>
PublishMessageWithTransaction
([
FromServices
]
ICapPublisher
publisher
)
[
Route
(
"~/publishWithTransactionUsingEF"
)]
public
async
Task
<
IActionResult
>
PublishMessageWithTransactionUsingEF
([
FromServices
]
AppDbContext
dbContext
,
[
FromServices
]
ICapPublisher
publisher
)
{
using
(
var
trans
=
dbContext
.
Database
.
BeginTransaction
())
{
// your business code
//Achieving atomicity between original database operation and the publish event log thanks to a local transaction
//If you are using EF, CAP will automatic discovery current environment transaction, so you do not need to explicit pass parameters.
//Achieving atomicity between original database operation and the publish event log thanks to a local transaction.
await
publisher
.
PublishAsync
(
"xxx.services.account.check"
,
new
Person
{
Name
=
"Foo"
,
Age
=
11
});
trans
.
Commit
();
}
return
Ok
();
}
[
Route
(
"~/publishWithTransactionUsingAdonet"
)]
public
async
Task
<
IActionResult
>
PublishMessageWithTransactionUsingAdonet
([
FromServices
]
ICapPublisher
publisher
)
{
var
connectionString
=
""
;
using
(
var
sqlConnection
=
new
SqlConnection
(
connectionString
))
{
sqlConnection
.
Open
();
using
(
var
sqlTransaction
=
sqlConnection
.
BeginTransaction
())
{
// your business code
publisher
.
Publish
(
"xxx.services.account.check"
,
new
Person
{
Name
=
"Foo"
,
Age
=
11
},
sqlTransaction
);
sqlTransaction
.
Commit
();
}
}
return
Ok
();
}
}
```
...
...
README.zh-cn.md
View file @
ae671216
...
...
@@ -98,27 +98,40 @@ public void Configure(IApplicationBuilder app)
```
c#
public
class
PublishController
:
Controller
{
private
readonly
AppDbContext
_dbContext
;
public
PublishController
(
AppDbContext
dbContext
)
{
_dbContext
=
dbContext
;
}
[
Route
(
"~/checkAccountWithTrans"
)]
public
async
Task
<
IActionResult
>
PublishMessageWithTransaction
([
FromServices
]
ICapPublisher
publisher
)
public
async
Task
<
IActionResult
>
PublishMessageWithTransaction
([
FromServices
]
AppDbContext
dbContext
,
[
FromServices
]
ICapPublisher
publisher
)
{
using
(
var
trans
=
dbContext
.
Database
.
BeginTransaction
())
{
//
your business code
//
此处填写你的业务代码
//Achieving atomicity between original database operation and the publish event log thanks to a local transaction
//如果你使用的是EF,CAP会自动发现当前环境中的事务,所以你必须显式传递事务参数。
//由于本地事务, 当前数据库的业务操作和发布事件日志之间将实现原子性。
await
publisher
.
PublishAsync
(
"xxx.services.account.check"
,
new
Person
{
Name
=
"Foo"
,
Age
=
11
});
trans
.
Commit
();
}
return
Ok
();
}
[
Route
(
"~/publishWithTransactionUsingAdonet"
)]
public
async
Task
<
IActionResult
>
PublishMessageWithTransactionUsingAdonet
([
FromServices
]
ICapPublisher
publisher
)
{
var
connectionString
=
""
;
using
(
var
sqlConnection
=
new
SqlConnection
(
connectionString
))
{
sqlConnection
.
Open
();
using
(
var
sqlTransaction
=
sqlConnection
.
BeginTransaction
())
{
// 此处填写你的业务代码,通常情况下,你可以将业务代码使用一个委托传递进来进行封装该区域代码。
publisher
.
Publish
(
"xxx.services.account.check"
,
new
Person
{
Name
=
"Foo"
,
Age
=
11
},
sqlTransaction
);
sqlTransaction
.
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