Skip to content

Instantly share code, notes, and snippets.

@Abdulsametileri
Created July 5, 2023 20:16
Show Gist options
  • Save Abdulsametileri/f4fb3fac4c1b33ef0a7b999becf9eac6 to your computer and use it in GitHub Desktop.
Save Abdulsametileri/f4fb3fac4c1b33ef0a7b999becf9eac6 to your computer and use it in GitHub Desktop.
kafka-konsumer/batch-consuming.go
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