我使用segmentio/kafka-go(v0.4.40)与kafka一起工作。
reader := kafka.NewReader(kafka.ReaderConfig{
Brokers: []string{broker},
GroupTopics: []string{topic},
GroupID: "group",
MinBytes: cfg.MinBytes,
MaxBytes: cfg.MaxBytes,
QueueCapacity: cfg.QueueCapacity,
SessionTimeout: cfg.SessionTimeout,
MaxAttempts: cfg.MaxAttempts,
Logger: kafka.LoggerFunc(log.New(log.Writer(), "[kafka reader] ", 0).Printf),
})
应用程序运行时,存储主题数据的目录被清除。日志中出现错误:
error initializing the Kafka reader for partition. Offset Output out of range: requested offset is outside the range offsets maintained by the server for the given topic\partition
我找到了问题的描述单击,消息显示已添加标志
OffsetOutOfRangeError
。
但我不明白这对解决方案有何帮助 - 在我看来,重新启动应用程序相当于在
OffsetOutOfRangeError=true
时收到的错误。但如果我重新启动应用程序,我仍然会遇到相同的错误。我该如何修复它们?
需要手动设置偏移量
./bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group --reset-offsets --topic --to-earliest --execute