-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add non transactional retry feature for only handling failed me…
…ssages * feat: add non transactional retry feature for only handling failed messages * chore: add tests * chore: lint * chore: lint * chore: add integration tests * chore: fix unit test * chore: fix integration test * chore: fix integration test * feat: little changes * feat: little changes --------- Co-authored-by: Abdulsametileri <sametileri07@gmail.com>
- Loading branch information
1 parent
a92ffd8
commit aa507a1
Showing
15 changed files
with
244 additions
and
55 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
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
File renamed without changes.
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,58 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"github.com/Trendyol/kafka-konsumer" | ||
"os" | ||
"os/signal" | ||
"time" | ||
) | ||
|
||
func main() { | ||
consumerCfg := &kafka.ConsumerConfig{ | ||
Reader: kafka.ReaderConfig{ | ||
Brokers: []string{"localhost:29092"}, | ||
Topic: "standart-topic", | ||
GroupID: "standart-cg", | ||
}, | ||
BatchConfiguration: &kafka.BatchConfiguration{ | ||
MessageGroupLimit: 1000, | ||
MessageGroupDuration: time.Second, | ||
BatchConsumeFn: batchConsumeFn, | ||
}, | ||
RetryEnabled: true, | ||
TransactionalRetry: kafka.NewBoolPtr(false), | ||
RetryConfiguration: kafka.RetryConfiguration{ | ||
Brokers: []string{"localhost:29092"}, | ||
Topic: "retry-topic", | ||
StartTimeCron: "*/5 * * * *", | ||
WorkDuration: 4 * time.Minute, | ||
MaxRetry: 3, | ||
}, | ||
} | ||
|
||
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 | ||
} | ||
|
||
// In order to load topic with data, use: | ||
// kafka-console-producer --broker-list localhost:29092 --topic standart-topic < examples/load.txt | ||
func batchConsumeFn(messages []*kafka.Message) error { | ||
// you can add custom error handling here & flag messages | ||
for i := range messages { | ||
if i%2 == 0 { | ||
messages[i].IsFailed = true | ||
} | ||
} | ||
|
||
// you must return error here to retry only failed messages | ||
return errors.New("err") | ||
} |
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
Oops, something went wrong.