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
43ee6268
Commit
43ee6268
authored
Oct 27, 2017
by
Savorboard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update readme
parent
2346bc20
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
23 deletions
+15
-23
README.md
README.md
+4
-5
README.zh-cn.md
README.zh-cn.md
+11
-18
No files found.
README.md
View file @
43ee6268
...
@@ -94,7 +94,7 @@ public void Configure(IApplicationBuilder app)
...
@@ -94,7 +94,7 @@ public void Configure(IApplicationBuilder app)
Inject
`ICapPublisher`
in your Controller, then use the
`ICapPublisher`
to send message
Inject
`ICapPublisher`
in your Controller, then use the
`ICapPublisher`
to send message
```
c
s
```
c
#
public
class
PublishController
:
Controller
public
class
PublishController
:
Controller
{
{
private
readonly
AppDbContext
_dbContext
;
private
readonly
AppDbContext
_dbContext
;
...
@@ -109,9 +109,9 @@ public class PublishController : Controller
...
@@ -109,9 +109,9 @@ public class PublishController : Controller
{
{
using
(
var
trans
=
dbContext
.
Database
.
BeginTransaction
())
using
(
var
trans
=
dbContext
.
Database
.
BeginTransaction
())
{
{
// your business code
// your business code
//Achieving atomicity between original database operation and the publish event log thanks to a local transaction
//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
});
await
publisher
.
PublishAsync
(
"xxx.services.account.check"
,
new
Person
{
Name
=
"Foo"
,
Age
=
11
});
trans
.
Commit
();
trans
.
Commit
();
...
@@ -128,10 +128,9 @@ public class PublishController : Controller
...
@@ -128,10 +128,9 @@ public class PublishController : Controller
Add the Attribute
`[CapSubscribe()]`
on Action to subscribe message:
Add the Attribute
`[CapSubscribe()]`
on Action to subscribe message:
```
c
s
```
c
#
public
class
PublishController
:
Controller
public
class
PublishController
:
Controller
{
{
[
NoAction
]
[
CapSubscribe
(
"xxx.services.account.check"
)]
[
CapSubscribe
(
"xxx.services.account.check"
)]
public
async
Task
CheckReceivedMessage
(
Person
person
)
public
async
Task
CheckReceivedMessage
(
Person
person
)
{
{
...
...
README.zh-cn.md
View file @
43ee6268
...
@@ -97,32 +97,25 @@ public void Configure(IApplicationBuilder app)
...
@@ -97,32 +97,25 @@ public void Configure(IApplicationBuilder app)
```
c#
```
c#
public
class
PublishController
:
Controller
public
class
PublishController
:
Controller
{
{
private
readonly
ICapPublisher
_publisher
;
private
readonly
AppDbContext
_dbContext
;
public
PublishController
(
ICapPublisher
publisher
)
{
_publisher
=
publisher
;
}
public
PublishController
(
AppDbContext
dbContext
)
[
Route
(
"~/checkAccount"
)]
public
async
Task
<
IActionResult
>
PublishMessage
()
{
{
//指定发送的消息头和内容
_dbContext
=
dbContext
;
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
();
}
}
return
Ok
();
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