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
27b59b8c
Commit
27b59b8c
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
e50ec84d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
62 deletions
+61
-62
README.md
README.md
+61
-62
No files found.
README.md
View file @
27b59b8c
...
@@ -60,34 +60,34 @@ First,You need to config CAP in your Startup.cs:
...
@@ -60,34 +60,34 @@ First,You need to config CAP in your Startup.cs:
```
cs
```
cs
public
void
ConfigureServices
(
IServiceCollection
services
)
public
void
ConfigureServices
(
IServiceCollection
services
)
{
{
......
//
......
services
.
AddDbContext
<
AppDbContext
>();
services
.
AddDbContext
<
AppDbContext
>();
services
.
AddCap
(
x
=>
services
.
AddCap
(
x
=>
{
{
// If you are using EF, you need to add the following configuration:
// If you are using EF, you need to add the following configuration:
// Notice: You don't need to config x.UseSqlServer(""") again! CAP can autodiscovery.
// Notice: You don't need to config x.UseSqlServer(""") again! CAP can autodiscovery.
x
.
UseEntityFramework
<
AppDbContext
>();
x
.
UseEntityFramework
<
AppDbContext
>();
// If you are using ado.net,you need to add the configuration:
// If you are using ado.net,you need to add the configuration:
x
.
UseSqlServer
(
"Your ConnectionStrings"
);
x
.
UseSqlServer
(
"Your ConnectionStrings"
);
x
.
UseMySql
(
"Your ConnectionStrings"
);
x
.
UseMySql
(
"Your ConnectionStrings"
);
x
.
UsePostgreSql
(
"Your ConnectionStrings"
);
x
.
UsePostgreSql
(
"Your ConnectionStrings"
);
// If you are using RabbitMQ, you need to add the configuration:
// If you are using RabbitMQ, you need to add the configuration:
x
.
UseRabbitMQ
(
"localhost"
);
x
.
UseRabbitMQ
(
"localhost"
);
// If you are using Kafka, you need to add the configuration:
// If you are using Kafka, you need to add the configuration:
x
.
UseKafka
(
"localhost"
);
x
.
UseKafka
(
"localhost"
);
});
});
}
}
public
void
Configure
(
IApplicationBuilder
app
)
public
void
Configure
(
IApplicationBuilder
app
)
{
{
.....
//
.....
app
.
UseCap
();
app
.
UseCap
();
}
}
```
```
...
@@ -99,27 +99,27 @@ Inject `ICapPublisher` in your Controller, then use the `ICapPublisher` to send
...
@@ -99,27 +99,27 @@ Inject `ICapPublisher` in your Controller, then use the `ICapPublisher` to send
```
c#
```
c#
public
class
PublishController
:
Controller
public
class
PublishController
:
Controller
{
{
private
readonly
AppDbContext
_dbContext
;
private
readonly
AppDbContext
_dbContext
;
public
PublishController
(
AppDbContext
dbContext
)
public
PublishController
(
AppDbContext
dbContext
)
{
{
_dbContext
=
dbContext
;
_dbContext
=
dbContext
;
}
}
[
Route
(
"~/checkAccountWithTrans"
)]
[
Route
(
"~/checkAccountWithTrans"
)]
public
async
Task
<
IActionResult
>
PublishMessageWithTransaction
([
FromServices
]
ICapPublisher
publisher
)
public
async
Task
<
IActionResult
>
PublishMessageWithTransaction
([
FromServices
]
ICapPublisher
publisher
)
{
{
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
();
}
}
return
Ok
();
return
Ok
();
}
}
}
}
```
```
...
@@ -133,13 +133,13 @@ Add the Attribute `[CapSubscribe()]` on Action to subscribe message:
...
@@ -133,13 +133,13 @@ Add the Attribute `[CapSubscribe()]` on Action to subscribe message:
```
c#
```
c#
public
class
PublishController
:
Controller
public
class
PublishController
:
Controller
{
{
[
CapSubscribe
(
"xxx.services.account.check"
)]
[
CapSubscribe
(
"xxx.services.account.check"
)]
public
async
Task
CheckReceivedMessage
(
Person
person
)
public
async
Task
CheckReceivedMessage
(
Person
person
)
{
{
Console
.
WriteLine
(
person
.
Name
);
Console
.
WriteLine
(
person
.
Name
);
Console
.
WriteLine
(
person
.
Age
);
Console
.
WriteLine
(
person
.
Age
);
return
Task
.
CompletedTask
;
return
Task
.
CompletedTask
;
}
}
}
}
```
```
...
@@ -148,34 +148,33 @@ public class PublishController : Controller
...
@@ -148,34 +148,33 @@ public class PublishController : Controller
If your subscribe method is not in the Controller,then your subscribe class need to Inheritance
`ICapSubscribe`
:
If your subscribe method is not in the Controller,then your subscribe class need to Inheritance
`ICapSubscribe`
:
```
c
s
```
c
#
namespace
xxx.Service
namespace
xxx.Service
{
{
public
interface
ISubscriberService
public
interface
ISubscriberService
{
{
public
void
CheckReceivedMessage
(
Person
person
);
public
void
CheckReceivedMessage
(
Person
person
);
}
}
public
class
SubscriberService
:
ISubscriberService
,
ICapSubscribe
{
[
CapSubscribe
(
"xxx.services.account.check"
)]
public
void
CheckReceivedMessage
(
Person
person
)
{
}
public
class
SubscriberService
:
ISubscriberService
,
ICapSubscribe
}
{
[
CapSubscribe
(
"xxx.services.account.check"
)]
public
void
CheckReceivedMessage
(
Person
person
)
{
}
}
}
}
```
```
Then inject your
`ISubscriberService`
class in Startup.cs
Then inject your
`ISubscriberService`
class in Startup.cs
```
c
s
```
c
#
public
void
ConfigureServices
(
IServiceCollection
services
)
public
void
ConfigureServices
(
IServiceCollection
services
)
{
{
services
.
AddTransient
<
ISubscriberService
,
SubscriberService
>();
services
.
AddTransient
<
ISubscriberService
,
SubscriberService
>();
}
}
```
```
...
...
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