github.com/Psiphon-Labs/goarista@v0.0.0-20160825065156-d002785f4c67/kafka/client.go (about)

     1  // Copyright (C) 2016  Arista Networks, Inc.
     2  // Use of this source code is governed by the Apache License 2.0
     3  // that can be found in the COPYING file.
     4  
     5  package kafka
     6  
     7  import (
     8  	"os"
     9  
    10  	"github.com/Shopify/sarama"
    11  )
    12  
    13  // NewClient returns a Kafka client
    14  func NewClient(addresses []string) (sarama.Client, error) {
    15  	config := sarama.NewConfig()
    16  	hostname, err := os.Hostname()
    17  	if err != nil {
    18  		hostname = ""
    19  	}
    20  	config.ClientID = hostname
    21  	config.Producer.Compression = sarama.CompressionSnappy
    22  	config.Producer.Return.Successes = true
    23  
    24  	return sarama.NewClient(addresses, config)
    25  }