Higher level abstraction for franz-go.
We want to be able to write our kafka applications without making the same things over and over.
Batch Consume
Consume messages as much as you defined.
Batch Produce
Produce messages as a batch to a topic.
For e2e example, check here.
producer, err := kafka.NewProducer("127.0.0.1:9092")
if err != nil {
log.Fatal(err)
}
defer producer.Close()
producer.Produce(context.Background(), []kafka.Message{
kafka.Message("message 1"),
kafka.Message("message 2"),
kafka.Message("message 3"),
kafka.Message("message 4"),
}, "messages")
consumer, err := kafka.NewConsumer("kafka_do", []string{"messages"}, []string{"127.0.0.1:9092"})
if err != nil {
log.Fatal(err)
}
defer consumer.Close()
messages, errs := consumer.ConsumeBatch(context.Background(), 2)
for _, message := range messages {
log.Println(message)
}
for _, err := range errs {
log.Println(err)
}
To run tests, start a kafka that runs on ":9092".
go test ./... -v -cover -count=1 -race