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
772a509c
Commit
772a509c
authored
Nov 27, 2019
by
Savorboard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add sync publish method with additional header
parent
d222559c
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
21 deletions
+44
-21
ICapPublisher.cs
src/DotNetCore.CAP/ICapPublisher.cs
+18
-3
ICapPublisher.Default.cs
src/DotNetCore.CAP/Internal/ICapPublisher.Default.cs
+21
-18
CAP.BuilderTest.cs
test/DotNetCore.CAP.Test/CAP.BuilderTest.cs
+5
-0
No files found.
src/DotNetCore.CAP/ICapPublisher.cs
View file @
772a509c
...
@@ -24,13 +24,20 @@ namespace DotNetCore.CAP
...
@@ -24,13 +24,20 @@ namespace DotNetCore.CAP
/// Asynchronous publish an object message.
/// Asynchronous publish an object message.
/// </summary>
/// </summary>
/// <param name="name">the topic name or exchange router key.</param>
/// <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="contentObj">message body content, that will be serialized.</param>
/// <param name="callbackName">callback subscriber name</param>
/// <param name="callbackName">callback subscriber name</param>
/// <param name="cancellationToken"></param>
/// <param name="cancellationToken"></param>
Task
PublishAsync
<
T
>(
string
name
,
T
contentObj
,
string
callbackName
=
null
,
CancellationToken
cancellationToken
=
default
);
Task
PublishAsync
<
T
>(
string
name
,
T
contentObj
,
string
callbackName
=
null
,
CancellationToken
cancellationToken
=
default
);
/// <summary>
Task
PublishAsync
<
T
>(
string
name
,
T
contentObj
,
IDictionary
<
string
,
string
>
optionHeaders
,
CancellationToken
cancellationToken
=
default
);
/// Asynchronous publish an object message with custom headers
/// </summary>
/// <typeparam name="T">content object</typeparam>
/// <param name="name">the topic name or exchange router key.</param>
/// <param name="contentObj">message body content, that will be serialized.</param>
/// <param name="headers">message additional headers.</param>
/// <param name="cancellationToken"></param>
Task
PublishAsync
<
T
>(
string
name
,
T
contentObj
,
IDictionary
<
string
,
string
>
headers
,
CancellationToken
cancellationToken
=
default
);
/// <summary>
/// <summary>
/// Publish an object message.
/// Publish an object message.
...
@@ -39,5 +46,13 @@ namespace DotNetCore.CAP
...
@@ -39,5 +46,13 @@ namespace DotNetCore.CAP
/// <param name="contentObj">message body content, that will be serialized of json.</param>
/// <param name="contentObj">message body content, that will be serialized of json.</param>
/// <param name="callbackName">callback subscriber name</param>
/// <param name="callbackName">callback subscriber name</param>
void
Publish
<
T
>(
string
name
,
T
contentObj
,
string
callbackName
=
null
);
void
Publish
<
T
>(
string
name
,
T
contentObj
,
string
callbackName
=
null
);
/// <summary>
/// Publish an 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="headers">message additional headers.</param>
void
Publish
<
T
>(
string
name
,
T
contentObj
,
IDictionary
<
string
,
string
>
headers
);
}
}
}
}
\ No newline at end of file
src/DotNetCore.CAP/Internal/ICapPublisher.Default.cs
View file @
772a509c
...
@@ -35,32 +35,30 @@ namespace DotNetCore.CAP.Internal
...
@@ -35,32 +35,30 @@ namespace DotNetCore.CAP.Internal
public
AsyncLocal
<
ICapTransaction
>
Transaction
{
get
;
}
public
AsyncLocal
<
ICapTransaction
>
Transaction
{
get
;
}
public
async
Task
PublishAsync
<
T
>(
string
name
,
T
value
,
public
async
Task
PublishAsync
<
T
>(
string
name
,
T
value
,
IDictionary
<
string
,
string
>
headers
,
CancellationToken
cancellationToken
=
default
)
IDictionary
<
string
,
string
>
optionHeaders
,
CancellationToken
cancellationToken
=
default
)
{
{
if
(
string
.
IsNullOrEmpty
(
name
))
if
(
string
.
IsNullOrEmpty
(
name
))
{
{
throw
new
ArgumentNullException
(
nameof
(
name
));
throw
new
ArgumentNullException
(
nameof
(
name
));
}
}
if
(
optionH
eaders
==
null
)
if
(
h
eaders
==
null
)
{
{
optionH
eaders
=
new
Dictionary
<
string
,
string
>();
h
eaders
=
new
Dictionary
<
string
,
string
>();
}
}
var
messageId
=
SnowflakeId
.
Default
().
NextId
().
ToString
();
var
messageId
=
SnowflakeId
.
Default
().
NextId
().
ToString
();
optionH
eaders
.
Add
(
Headers
.
MessageId
,
messageId
);
h
eaders
.
Add
(
Headers
.
MessageId
,
messageId
);
optionH
eaders
.
Add
(
Headers
.
MessageName
,
name
);
h
eaders
.
Add
(
Headers
.
MessageName
,
name
);
optionH
eaders
.
Add
(
Headers
.
Type
,
typeof
(
T
).
FullName
);
h
eaders
.
Add
(
Headers
.
Type
,
typeof
(
T
).
FullName
);
optionH
eaders
.
Add
(
Headers
.
SentTime
,
DateTimeOffset
.
Now
.
ToString
());
h
eaders
.
Add
(
Headers
.
SentTime
,
DateTimeOffset
.
Now
.
ToString
());
if
(!
optionH
eaders
.
ContainsKey
(
Headers
.
CorrelationId
))
if
(!
h
eaders
.
ContainsKey
(
Headers
.
CorrelationId
))
{
{
optionH
eaders
.
Add
(
Headers
.
CorrelationId
,
messageId
);
h
eaders
.
Add
(
Headers
.
CorrelationId
,
messageId
);
optionH
eaders
.
Add
(
Headers
.
CorrelationSequence
,
0.
ToString
());
h
eaders
.
Add
(
Headers
.
CorrelationSequence
,
0.
ToString
());
}
}
var
message
=
new
Message
(
optionH
eaders
,
value
);
var
message
=
new
Message
(
h
eaders
,
value
);
long
?
tracingTimestamp
=
null
;
long
?
tracingTimestamp
=
null
;
try
try
...
@@ -99,11 +97,6 @@ namespace DotNetCore.CAP.Internal
...
@@ -99,11 +97,6 @@ namespace DotNetCore.CAP.Internal
}
}
}
}
public
void
Publish
<
T
>(
string
name
,
T
value
,
string
callbackName
=
null
)
{
PublishAsync
(
name
,
value
,
callbackName
).
GetAwaiter
().
GetResult
();
}
public
Task
PublishAsync
<
T
>(
string
name
,
T
value
,
string
callbackName
=
null
,
public
Task
PublishAsync
<
T
>(
string
name
,
T
value
,
string
callbackName
=
null
,
CancellationToken
cancellationToken
=
default
)
CancellationToken
cancellationToken
=
default
)
{
{
...
@@ -115,6 +108,16 @@ namespace DotNetCore.CAP.Internal
...
@@ -115,6 +108,16 @@ namespace DotNetCore.CAP.Internal
return
PublishAsync
(
name
,
value
,
header
,
cancellationToken
);
return
PublishAsync
(
name
,
value
,
header
,
cancellationToken
);
}
}
public
void
Publish
<
T
>(
string
name
,
T
value
,
string
callbackName
=
null
)
{
PublishAsync
(
name
,
value
,
callbackName
).
GetAwaiter
().
GetResult
();
}
public
void
Publish
<
T
>(
string
name
,
T
value
,
IDictionary
<
string
,
string
>
headers
)
{
PublishAsync
(
name
,
value
,
headers
).
GetAwaiter
().
GetResult
();
}
#
region
tracing
#
region
tracing
private
long
?
TracingBefore
(
Message
message
)
private
long
?
TracingBefore
(
Message
message
)
...
...
test/DotNetCore.CAP.Test/CAP.BuilderTest.cs
View file @
772a509c
...
@@ -84,6 +84,11 @@ namespace DotNetCore.CAP.Test
...
@@ -84,6 +84,11 @@ namespace DotNetCore.CAP.Test
{
{
throw
new
NotImplementedException
();
throw
new
NotImplementedException
();
}
}
public
void
Publish
<
T
>(
string
name
,
T
contentObj
,
IDictionary
<
string
,
string
>
headers
)
{
throw
new
NotImplementedException
();
}
}
}
}
}
}
}
\ No newline at end of file
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