You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
564 B

2 years ago
package main
import (
"context"
"fmt"
"log"
kafka "github.com/segmentio/kafka-go"
)
func main() {
2 years ago
ctx := context.Background()
2 years ago
consumer := kafka.NewReader(kafka.ReaderConfig{
2 years ago
Brokers: []string{"localhost:9092"},
2 years ago
Topic: "topic-A",
Partition: 0,
MinBytes: 10e3, // 10KB
MaxBytes: 10e6, // 10MB
2 years ago
})
2 years ago
defer consumer.Close()
//
// consumer.SetOffset(42)
2 years ago
2 years ago
//
2 years ago
for {
2 years ago
m, err := consumer.ReadMessage(ctx)
2 years ago
if err != nil {
2 years ago
log.Fatal(err)
2 years ago
}
2 years ago
fmt.Printf("message at offset %d: %s = %s\n", m.Offset, string(m.Key), string(m.Value))
2 years ago
}
}