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
2346bc20
Commit
2346bc20
authored
Oct 27, 2017
by
Savorboard
Committed by
GitHub
Oct 27, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update README.md
parent
5c2f2e3b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
15 deletions
+8
-15
README.md
README.md
+8
-15
No files found.
README.md
View file @
2346bc20
...
@@ -97,29 +97,22 @@ Inject `ICapPublisher` in your Controller, then use the `ICapPublisher` to send
...
@@ -97,29 +97,22 @@ Inject `ICapPublisher` in your Controller, then use the `ICapPublisher` to send
```
cs
```
cs
public
class
PublishController
:
Controller
public
class
PublishController
:
Controller
{
{
private
readonly
ICapPublisher
_publisher
;
private
readonly
AppDbContext
_dbContext
;
public
PublishController
(
ICapPublisher
publisher
)
public
PublishController
(
AppDbContext
dbContext
)
{
{
_publisher
=
publisher
;
_dbContext
=
dbContext
;
}
[
Route
(
"~/checkAccount"
)]
public
async
Task
<
IActionResult
>
PublishMessage
()
{
// Specifies the message header and content to be sent
await
_publisher
.
PublishAsync
(
"xxx.services.account.check"
,
new
Person
{
Name
=
"Foo"
,
Age
=
11
});
return
Ok
();
}
}
[
Route
(
"~/checkAccountWithTrans"
)]
[
Route
(
"~/checkAccountWithTrans"
)]
public
async
Task
<
IActionResult
>
PublishMessageWithTransaction
([
FromServices
]
AppDbContext
dbContext
)
public
async
Task
<
IActionResult
>
PublishMessageWithTransaction
([
FromServices
]
ICapPublisher
publisher
)
{
{
using
(
var
trans
=
dbContext
.
Database
.
BeginTransaction
())
using
(
var
trans
=
dbContext
.
Database
.
BeginTransaction
())
{
{
await
_publisher
.
PublishAsync
(
"xxx.services.account.check"
,
new
Person
{
Name
=
"Foo"
,
Age
=
11
});
// your business code
//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
();
trans
.
Commit
();
}
}
...
...
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