-
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 header filter feature (#105)
* feat: add header filter feature * chore: add skipMessageByHeaderFn to the README.md * chore: fix lint
- Loading branch information
1 parent
9ec9054
commit 15a97a2
Showing
7 changed files
with
158 additions
and
4 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
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,47 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/Trendyol/kafka-konsumer/v2" | ||
"os" | ||
"os/signal" | ||
) | ||
|
||
func main() { | ||
consumerCfg := &kafka.ConsumerConfig{ | ||
Concurrency: 1, | ||
Reader: kafka.ReaderConfig{ | ||
Brokers: []string{"localhost:29092"}, | ||
Topic: "standart-topic", | ||
GroupID: "standart-cg", | ||
}, | ||
RetryEnabled: false, | ||
SkipMessageByHeaderFn: skipMessageByHeaderFn, | ||
ConsumeFn: consumeFn, | ||
} | ||
|
||
consumer, _ := kafka.NewConsumer(consumerCfg) | ||
defer consumer.Stop() | ||
|
||
consumer.Consume() | ||
|
||
fmt.Println("Consumer started...!") | ||
|
||
c := make(chan os.Signal, 1) | ||
signal.Notify(c, os.Interrupt) | ||
<-c | ||
} | ||
|
||
func skipMessageByHeaderFn(headers []kafka.Header) bool { | ||
for _, header := range headers { | ||
if header.Key == "SkipMessage" { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
func consumeFn(message *kafka.Message) error { | ||
fmt.Printf("Message From %s with value %s\n", message.Topic, string(message.Value)) | ||
return nil | ||
} |
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