本文整理汇总了Golang中github.com/Shopify/sarama.Broker.CommitOffset方法的典型用法代码示例。如果您正苦于以下问题:Golang Broker.CommitOffset方法的具体用法?Golang Broker.CommitOffset怎么用?Golang Broker.CommitOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/Shopify/sarama.Broker
的用法示例。
在下文中一共展示了Broker.CommitOffset方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: commitOffset
// commitOffset sends an offset message to kafka for the given consumer group
func commitOffset(broker *sarama.Broker, topic string, partition int32, group string, offset int64, generationID int32, memberID string) {
v := int16(0)
if config.offset.version.IsAtLeast(sarama.V0_8_2_0) {
v = 1
}
if config.offset.version.IsAtLeast(sarama.V0_9_0_0) {
v = 2
}
req := &sarama.OffsetCommitRequest{
Version: v,
ConsumerGroup: group,
ConsumerGroupGeneration: generationID,
ConsumerID: memberID,
RetentionTime: -1,
}
req.AddBlock(topic, partition, offset, 0, "")
offsetResp, err := broker.CommitOffset(req)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to commit offsets. err=%v\n", err)
os.Exit(1)
} else if len(offsetResp.Errors) > 0 {
for topic, perrs := range offsetResp.Errors {
for partition, kerr := range perrs {
if kerr != sarama.ErrNoError {
fmt.Fprintf(os.Stderr, "Failed to commit offsets topic=%s, partition=%s. err=%v\n", topic, partition, err)
os.Exit(1)
}
}
}
}
}