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
8485fb2f
Commit
8485fb2f
authored
Aug 20, 2018
by
Savorboard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rename CapTransaction to Transaction
parent
2f6b3502
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
28 additions
and
15 deletions
+28
-15
ValuesController.cs
...les/Sample.RabbitMQ.MySql/Controllers/ValuesController.cs
+15
-2
CapPublisherBase.cs
src/DotNetCore.CAP/Abstractions/CapPublisherBase.cs
+11
-11
ICapPublisher.cs
src/DotNetCore.CAP/ICapPublisher.cs
+1
-1
CAP.BuilderTest.cs
test/DotNetCore.CAP.Test/CAP.BuilderTest.cs
+1
-1
No files found.
samples/Sample.RabbitMQ.MySql/Controllers/ValuesController.cs
View file @
8485fb2f
...
...
@@ -2,6 +2,7 @@
using
System.Threading.Tasks
;
using
DotNetCore.CAP
;
using
Microsoft.AspNetCore.Mvc
;
using
MySql.Data.MySqlClient
;
namespace
Sample.RabbitMQ.MySql.Controllers
{
...
...
@@ -28,7 +29,17 @@ namespace Sample.RabbitMQ.MySql.Controllers
[
Route
(
"~/publish2"
)]
public
IActionResult
PublishMessage2
()
{
_capBus
.
Publish
(
"sample.kafka.sqlserver4"
,
DateTime
.
Now
);
using
(
var
connection
=
new
MySqlConnection
(
"Server=192.168.10.110;Database=testcap;UserId=root;Password=123123;"
))
{
using
(
var
transaction
=
connection
.
BeginAndJoinToTransaction
(
_capBus
))
{
//your business code
_capBus
.
Publish
(
"sample.rabbitmq.mysql"
,
DateTime
.
Now
);
transaction
.
Commit
();
}
}
return
Ok
();
}
...
...
@@ -37,7 +48,7 @@ namespace Sample.RabbitMQ.MySql.Controllers
public
async
Task
<
IActionResult
>
PublishMessageWithTransaction
()
{
using
(
var
trans
=
await
_dbContext
.
Database
.
BeginTransactionAsync
())
using
(
var
capTrans
=
_capBus
.
Cap
Transaction
.
Begin
(
trans
))
using
(
var
capTrans
=
_capBus
.
Transaction
.
Begin
(
trans
))
{
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
...
...
@@ -49,6 +60,8 @@ namespace Sample.RabbitMQ.MySql.Controllers
return
Ok
();
}
[
NonAction
]
[
CapSubscribe
(
"#.rabbitmq.mysql"
)]
public
void
ReceiveMessage
(
DateTime
time
)
...
...
src/DotNetCore.CAP/Abstractions/CapPublisherBase.cs
View file @
8485fb2f
...
...
@@ -14,7 +14,7 @@ namespace DotNetCore.CAP.Abstractions
{
public
abstract
class
CapPublisherBase
:
ICapPublisher
{
private
readonly
CapTransactionBase
_
capT
ransaction
;
private
readonly
CapTransactionBase
_
t
ransaction
;
private
readonly
IMessagePacker
_msgPacker
;
private
readonly
IContentSerializer
_serializer
;
...
...
@@ -27,14 +27,14 @@ namespace DotNetCore.CAP.Abstractions
protected
CapPublisherBase
(
IServiceProvider
service
)
{
ServiceProvider
=
service
;
_
capT
ransaction
=
service
.
GetRequiredService
<
CapTransactionBase
>();
_
t
ransaction
=
service
.
GetRequiredService
<
CapTransactionBase
>();
_msgPacker
=
service
.
GetRequiredService
<
IMessagePacker
>();
_serializer
=
service
.
GetRequiredService
<
IContentSerializer
>();
}
protected
IServiceProvider
ServiceProvider
{
get
;
}
public
ICapTransaction
CapTransaction
=>
_capT
ransaction
;
public
ICapTransaction
Transaction
=>
_t
ransaction
;
public
void
Publish
<
T
>(
string
name
,
T
contentObj
,
string
callbackName
=
null
)
{
...
...
@@ -65,10 +65,10 @@ namespace DotNetCore.CAP.Abstractions
protected
async
Task
PublishAsyncInternal
(
CapPublishedMessage
message
)
{
if
(
Cap
Transaction
.
DbTransaction
==
null
)
if
(
Transaction
.
DbTransaction
==
null
)
{
NotUseTransaction
=
true
;
Cap
Transaction
.
DbTransaction
=
GetDbTransaction
();
Transaction
.
DbTransaction
=
GetDbTransaction
();
}
Guid
operationId
=
default
(
Guid
);
...
...
@@ -77,15 +77,15 @@ namespace DotNetCore.CAP.Abstractions
{
operationId
=
s_diagnosticListener
.
WritePublishMessageStoreBefore
(
message
);
await
ExecuteAsync
(
message
,
Cap
Transaction
);
await
ExecuteAsync
(
message
,
Transaction
);
_
capT
ransaction
.
AddToSent
(
message
);
_
t
ransaction
.
AddToSent
(
message
);
s_diagnosticListener
.
WritePublishMessageStoreAfter
(
operationId
,
message
);
if
(
NotUseTransaction
||
Cap
Transaction
.
AutoCommit
)
if
(
NotUseTransaction
||
Transaction
.
AutoCommit
)
{
_
capT
ransaction
.
Commit
();
_
t
ransaction
.
Commit
();
}
}
catch
(
Exception
e
)
...
...
@@ -96,9 +96,9 @@ namespace DotNetCore.CAP.Abstractions
}
finally
{
if
(
NotUseTransaction
||
Cap
Transaction
.
AutoCommit
)
if
(
NotUseTransaction
||
Transaction
.
AutoCommit
)
{
_
capT
ransaction
.
Dispose
();
_
t
ransaction
.
Dispose
();
}
}
}
...
...
src/DotNetCore.CAP/ICapPublisher.cs
View file @
8485fb2f
...
...
@@ -11,7 +11,7 @@ namespace DotNetCore.CAP
/// </summary>
public
interface
ICapPublisher
{
ICapTransaction
Cap
Transaction
{
get
;
}
ICapTransaction
Transaction
{
get
;
}
/// <summary>
/// Asynchronous publish an object message.
...
...
test/DotNetCore.CAP.Test/CAP.BuilderTest.cs
View file @
8485fb2f
...
...
@@ -119,7 +119,7 @@ namespace DotNetCore.CAP.Test
private
class
MyProducerService
:
ICapPublisher
{
public
ICapTransaction
Cap
Transaction
{
get
;
}
public
ICapTransaction
Transaction
{
get
;
}
public
Task
PublishAsync
<
T
>(
string
name
,
T
contentObj
,
string
callbackName
=
null
,
CancellationToken
cancellationToken
=
default
(
CancellationToken
))
...
...
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