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
d97f1f7f
Commit
d97f1f7f
authored
Oct 31, 2017
by
Savorboard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
optimizing publisher interface
parent
0f146b81
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
30 deletions
+25
-30
CapPublisherBase.cs
src/DotNetCore.CAP/Abstractions/CapPublisherBase.cs
+19
-20
ICapPublisher.cs
src/DotNetCore.CAP/ICapPublisher.cs
+4
-8
CAP.BuilderTest.cs
test/DotNetCore.CAP.Test/CAP.BuilderTest.cs
+2
-2
No files found.
src/DotNetCore.CAP/Abstractions/CapPublisherBase.cs
View file @
d97f1f7f
...
...
@@ -36,22 +36,20 @@ namespace DotNetCore.CAP.Abstractions
return
PublishWithTransAsync
(
name
,
content
);
}
public
void
Publish
<
T
>(
string
name
,
T
contentObj
,
IDbConnection
dbConnection
,
string
callbackName
=
null
,
IDbTransaction
dbTransaction
=
null
)
public
void
Publish
<
T
>(
string
name
,
T
contentObj
,
IDbTransaction
dbTransaction
,
string
callbackName
=
null
)
{
CheckIsAdoNet
(
name
);
PrepareConnectionForAdo
(
db
Connection
,
db
Transaction
);
PrepareConnectionForAdo
(
dbTransaction
);
var
content
=
Serialize
(
contentObj
,
callbackName
);
PublishWithTrans
(
name
,
content
);
}
public
Task
PublishAsync
<
T
>(
string
name
,
T
contentObj
,
IDbConnection
dbConnection
,
string
callbackName
=
null
,
IDbTransaction
dbTransaction
=
null
)
public
Task
PublishAsync
<
T
>(
string
name
,
T
contentObj
,
IDbTransaction
dbTransaction
,
string
callbackName
=
null
)
{
CheckIsAdoNet
(
name
);
PrepareConnectionForAdo
(
db
Connection
,
db
Transaction
);
PrepareConnectionForAdo
(
dbTransaction
);
var
content
=
Serialize
(
contentObj
,
callbackName
);
...
...
@@ -69,16 +67,22 @@ namespace DotNetCore.CAP.Abstractions
protected
virtual
string
Serialize
<
T
>(
T
obj
,
string
callbackName
=
null
)
{
var
packer
=
(
IMessagePacker
)
ServiceProvider
.
GetService
(
typeof
(
IMessagePacker
));
string
content
=
string
.
Empty
;
if
(
Helper
.
IsComplexType
(
obj
.
GetType
()))
string
content
;
if
(
obj
!=
null
)
{
var
serializer
=
(
IContentSerializer
)
ServiceProvider
.
GetService
(
typeof
(
IContentSerializer
));
content
=
serializer
.
Serialize
(
obj
);
if
(
Helper
.
IsComplexType
(
obj
.
GetType
()))
{
var
serializer
=
(
IContentSerializer
)
ServiceProvider
.
GetService
(
typeof
(
IContentSerializer
));
content
=
serializer
.
Serialize
(
obj
);
}
else
{
content
=
obj
.
ToString
();
}
}
else
{
content
=
obj
?.
ToString
()
;
content
=
string
.
Empty
;
}
var
message
=
new
CapMessageDto
(
content
)
...
...
@@ -91,20 +95,15 @@ namespace DotNetCore.CAP.Abstractions
#
region
private
methods
private
void
PrepareConnectionForAdo
(
IDb
Connection
dbConnection
,
IDb
Transaction
dbTransaction
)
private
void
PrepareConnectionForAdo
(
IDbTransaction
dbTransaction
)
{
DbConnection
=
dbConnection
??
throw
new
ArgumentNullException
(
nameof
(
dbConnection
));
DbTransaction
=
dbTransaction
??
throw
new
ArgumentNullException
(
nameof
(
dbTransaction
));
DbConnection
=
DbTransaction
.
Connection
;
if
(
DbConnection
.
State
!=
ConnectionState
.
Open
)
{
IsCapOpenedConn
=
true
;
DbConnection
.
Open
();
}
DbTransaction
=
dbTransaction
;
if
(
DbTransaction
==
null
)
{
IsCapOpenedTrans
=
true
;
DbTransaction
=
dbConnection
.
BeginTransaction
(
IsolationLevel
.
ReadCommitted
);
}
}
private
void
CheckIsUsingEF
(
string
name
)
...
...
src/DotNetCore.CAP/ICapPublisher.cs
View file @
d97f1f7f
...
...
@@ -39,21 +39,17 @@ namespace DotNetCore.CAP
/// </summary>
/// <param name="name">the topic name or exchange router key.</param>
/// <param name="contentObj">message body content, that will be serialized of json.</param>
/// <param name="callbackName">callback subscriber name</param>
/// <param name="dbConnection">the connection of <see cref="IDbConnection" /></param>
/// <param name="dbTransaction">the transaction of <see cref="IDbTransaction" /></param>
Task
PublishAsync
<
T
>(
string
name
,
T
contentObj
,
IDbConnection
dbConnection
,
string
callbackName
=
null
,
IDbTransaction
dbTransaction
=
null
);
/// <param name="callbackName">callback subscriber name</param>
Task
PublishAsync
<
T
>(
string
name
,
T
contentObj
,
IDbTransaction
dbTransaction
,
string
callbackName
=
null
);
/// <summary>
/// (ado.net) Publish a object message.
/// </summary>
/// <param name="name">the topic name or exchange router key.</param>
/// <param name="contentObj">message body content, that will be serialized of json.</param>
/// <param name="callbackName">callback subscriber name</param>
/// <param name="dbConnection">the connection of <see cref="IDbConnection" /></param>
/// <param name="dbTransaction">the transaction of <see cref="IDbTransaction" /></param>
void
Publish
<
T
>(
string
name
,
T
contentObj
,
IDbConnection
dbConnection
,
string
callbackName
=
null
,
IDbTransaction
dbTransaction
=
null
);
/// <param name="callbackName">callback subscriber name</param>
void
Publish
<
T
>(
string
name
,
T
contentObj
,
IDbTransaction
dbTransaction
,
string
callbackName
=
null
);
}
}
\ No newline at end of file
test/DotNetCore.CAP.Test/CAP.BuilderTest.cs
View file @
d97f1f7f
...
...
@@ -124,7 +124,7 @@ namespace DotNetCore.CAP.Test
throw
new
NotImplementedException
();
}
public
void
Publish
<
T
>(
string
name
,
T
contentObj
,
IDb
Connection
dbConnection
,
string
callbackName
=
null
,
IDbTransaction
dbTransaction
=
null
)
public
void
Publish
<
T
>(
string
name
,
T
contentObj
,
IDb
Transaction
dbTransaction
,
string
callbackName
=
null
)
{
throw
new
NotImplementedException
();
}
...
...
@@ -159,7 +159,7 @@ namespace DotNetCore.CAP.Test
throw
new
NotImplementedException
();
}
public
Task
PublishAsync
<
T
>(
string
name
,
T
contentObj
,
IDb
Connection
dbConnection
,
string
callbackName
=
null
,
IDbTransaction
dbTransaction
=
null
)
public
Task
PublishAsync
<
T
>(
string
name
,
T
contentObj
,
IDb
Transaction
dbTransaction
,
string
callbackName
=
null
)
{
throw
new
NotImplementedException
();
}
...
...
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