Advertisement

go和kafka(github.com/Shopify/sarama)

阅读量:

启动kafka

依次通过命令行界面启动zookeeper与kafka服务

复制代码
 .\bin\windows\zookeeper-server-start.bat .\config\zookeeper.properties

    
 .\bin\windows\kafka-server-start.bat .\config\server.properties
    
    
    
    

生产者角色与功能分析

复制代码
 import (

    
 	"fmt"
    
 	"github.com/Shopify/sarama"
    
 )
    
  
    
 func main() {
    
 	config := sarama.NewConfig()
    
 	config.Producer.RequiredAcks = sarama.WaitForAll  //赋值为-1:这意味着producer在follower副本确认接收到数据后才算一次发送完成。
    
 	config.Producer.Partitioner = sarama.NewRandomPartitioner  //写到随机分区中,默认设置8个分区
    
 	config.Producer.Return.Successes =

全部评论 (0)

还没有任何评论哟~