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
e15f5185
Commit
e15f5185
authored
Dec 12, 2019
by
Savorboard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Kafka options to support custom header to add offset and partition into CapHeader. #374
parent
d2093f3c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
0 deletions
+15
-0
CAP.KafkaOptions.cs
src/DotNetCore.CAP.Kafka/CAP.KafkaOptions.cs
+6
-0
KafkaConsumerClient.cs
src/DotNetCore.CAP.Kafka/KafkaConsumerClient.cs
+9
-0
No files found.
src/DotNetCore.CAP.Kafka/CAP.KafkaOptions.cs
View file @
e15f5185
...
...
@@ -5,6 +5,7 @@ using System;
using
System.Collections.Concurrent
;
using
System.Collections.Generic
;
using
System.Linq
;
using
Confluent.Kafka
;
// ReSharper disable once CheckNamespace
namespace
DotNetCore.CAP
...
...
@@ -43,6 +44,11 @@ namespace DotNetCore.CAP
/// </summary>
public
string
Servers
{
get
;
set
;
}
/// <summary>
/// If you need to get offset and partition and so on.., you can use this function to write additional header into <see cref="CapHeader"/>
/// </summary>
public
Func
<
ConsumeResult
<
string
,
byte
[
]>
,
List
<
KeyValuePair
<
string
,
string
>>>
CustomHeaders
{
get
;
set
;
}
internal
IEnumerable
<
KeyValuePair
<
string
,
string
>>
AsKafkaConfig
()
{
if
(
_kafkaConfig
==
null
)
...
...
src/DotNetCore.CAP.Kafka/KafkaConsumerClient.cs
View file @
e15f5185
...
...
@@ -62,6 +62,15 @@ namespace DotNetCore.CAP.Kafka
}
headers
.
Add
(
Messages
.
Headers
.
Group
,
_groupId
);
if
(
_kafkaOptions
.
CustomHeaders
!=
null
)
{
var
customHeaders
=
_kafkaOptions
.
CustomHeaders
(
consumerResult
);
foreach
(
var
customHeader
in
customHeaders
)
{
headers
.
Add
(
customHeader
.
Key
,
customHeader
.
Value
);
}
}
var
message
=
new
TransportMessage
(
headers
,
consumerResult
.
Value
);
OnMessageReceived
?.
Invoke
(
consumerResult
,
message
);
...
...
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