Created
July 5, 2023 20:16
-
-
Save Abdulsametileri/f4fb3fac4c1b33ef0a7b999becf9eac6 to your computer and use it in GitHub Desktop.
kafka-konsumer/batch-consuming.go
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
func main() { | |
consumerCfg := &kafka.ConsumerConfig{ | |
Reader: kafka.ReaderConfig{ | |
Brokers: []string{"localhost:29092"}, | |
Topic: "standart-topic", | |
GroupID: "standart-cg", | |
}, | |
RetryEnabled: true, | |
RetryConfiguration: kafka.RetryConfiguration{ | |
Brokers: []string{"localhost:29092"}, | |
Topic: "retry-topic", | |
StartTimeCron: "*/1 * * * *", | |
WorkDuration: 50 * time.Second, | |
MaxRetry: 3, | |
}, | |
BatchConfiguration: kafka.BatchConfiguration{ | |
MessageGroupLimit: 1000, | |
MessageGroupDuration: time.Second, | |
BatchConsumeFn: batchConsumeFn, | |
}, | |
} | |
consumer, _ := kafka.NewConsumer(consumerCfg) | |
defer consumer.Stop() | |
consumer.Consume() | |
} | |
func batchConsumeFn(messages []kafka.Message) error { | |
fmt.Printf("%d\n comes first %s", len(messages), messages[0].Value) | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment