简体   繁体   English

我们如何使用 confluent-kafka-go 客户端确保可靠和低延迟的 kafka 编写?

[英]How can we ensure reliable and low-latency kafka writing using confluent-kafka-go client?

The sample producer code at https://github.com/confluentinc/confluent-kafka-go calls Producer.Produce(...) It writes the message to the sending buffer queue and return immediately. https://github.com/confluentinc/confluent-kafka-go上的示例生产者代码调用Producer.Produce(...)它将消息写入发送缓冲区队列并立即返回。 However, writing to the internal buffer queue does not guarantee successful message delivery.但是,写入内部缓冲区队列并不能保证消息传递成功。 How can we ensure sucessful message delivery here?我们如何确保在这里成功传递消息?

for idx, word := range []string{"Welcome", "to", "the", 
                                "Confluent", "Kafka", "Golang", "client"} {
    start_time := time.Now().UnixNano()
    p.Produce(&kafka.Message{
        TopicPartition: kafka.TopicPartition{Topic: &topic, 
                                             Partition: kafka.PartitionAny},
        Value:          []byte(word),
    }, nil)
}

To block and send data immediately, you'd call Flush method of the producer要立即阻止和发送数据,您需要调用生产者的 Flush 方法

https://github.com/confluentinc/confluent-kafka-go/blob/master/kafka/producer.go#L335 https://github.com/confluentinc/confluent-kafka-go/blob/master/kafka/producer.go#L335

To ensure it's written reliably, set acks=all producer config and ensure the topic is configured to have min in sync replicas as 2 or more, and topic replication factor as 3 or more为确保其写入可靠,请设置 acks=all 生产者配置并确保将主题配置为具有最小同步副本为 2 或更多,主题复制因子为 3 或更多

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM