-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add producer interceptor interface
- Loading branch information
Showing
10 changed files
with
217 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package kafka | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
type BatchProducerInterceptorContext struct { | ||
Context context.Context | ||
Message *Message | ||
} | ||
|
||
type BatchProducerInterceptor interface { | ||
OnProduce(ctx context.Context, msg Message) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package kafka | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
type ProducerInterceptorContext struct { | ||
Context context.Context | ||
Message *Message | ||
} | ||
|
||
type ProducerInterceptor interface { | ||
OnProduce(ctx ProducerInterceptorContext) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package test | ||
|
||
import "github.com/Trendyol/kafka-konsumer/v2" | ||
|
||
type MockProducerInterceptor struct{} | ||
|
||
const ( | ||
XSourceAppKey = "x-source-app" | ||
XSourceAppValue = "kafka-konsumer" | ||
) | ||
|
||
func (i *MockProducerInterceptor) OnProduce(ctx kafka.ProducerInterceptorContext) { | ||
ctx.Message.Headers = append(ctx.Message.Headers, kafka.Header{ | ||
Key: XSourceAppKey, | ||
Value: []byte(XSourceAppValue), | ||
}) | ||
} | ||
|
||
func NewMockProducerInterceptor() kafka.ProducerInterceptor { | ||
return &MockProducerInterceptor{} | ||
} |