“ [56] Kafka存储错误:尝试访问磁盘上的日志文件时出现磁盘错误”

时间:2019-04-14 16:02:53

标签: go apache-kafka kafka-consumer-api

我正在尝试使用带有Go的Kafka构建一个简单的演示,但出现此错误: [56] Kafka Storage Error: disk error when trying to access log file on the disk

我正在使用https://github.com/segmentio/kafka-go,下面是我的代码。谁能帮助解决此错误?

func main() {

    // to produce messages
    topic := "test-1"
    partition := 0
    fmt.Println("before connection")

    conn, _ := kafka.DialLeader(context.Background(), "tcp", "localhost:9092", topic, partition)
    conn.SetWriteDeadline(time.Now().Add(10*time.Second));

    conn.WriteMessages(
        kafka.Message{Value: []byte("one!")},
        kafka.Message{Value: []byte("two!")},
        kafka.Message{Value: []byte("three!")},
    )
    fmt.Println("afterWriteMessages")

    r := kafka.NewReader(kafka.ReaderConfig{
        Brokers:   []string{"localhost:9092"},
        Topic:     topic,
        Partition: 0,
        MinBytes:  10e3, // 10KB
        MaxBytes:  10e6, // 10MB
    })

    r.SetOffset(0)

    for {
        m, err := r.ReadMessage(context.Background())
        if err != nil {
            fmt.Println("err", err)
            break
        }
        fmt.Printf("message at offset %d: %s = %s\n", m.Offset, string(m.Key), string(m.Value))
    }

    r.Close()
    defer conn.Close()
}

0 个答案:

没有答案