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.
 
 
 
 
 

34 lines
564 B

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