func (s *NetIntegrationSuiteParallelG) TestKafkaLivenessBySarama() {
	msgValue := "testing message " + uuid.New()
	producer, partition, err := s.produceKafkaMessage(msgValue)
	if err != nil {
		return
	}
	defer func() {
		err := producer.Close()
		s.Assert().Nil(err)
	}()
	brokers := []string{"localhost:9092"}
	topic := "test_topic_01"
	consumer, err := sarama.NewConsumer(brokers, nil)
	s.Assert().Nil(err)
	if err != nil {
		return
	}
	defer func() {
		err := consumer.Close()
		s.Assert().Nil(err)
	}()
	partitionConsumer, err := consumer.ConsumePartition(topic, partition, sarama.OffsetOldest)
	s.Assert().Nil(err)
	var receivedMessage = false
FOR:
	for {
		select {
		case err := <-partitionConsumer.Errors():
			log.Printf("Failed to receive message: %s\n", err)
		case msg := <-partitionConsumer.Messages():
			if string(msg.Value) == msgValue {
				receivedMessage = true
				log.Printf("Received message at partition %d at offset %d: %s\n", msg.Partition, msg.Offset, string(msg.Value))
				break FOR
			}
		case <-time.After(time.Second * 3):
			break FOR
		}
	}
	s.Assert().True(receivedMessage)
}
Note: you need to start ZooKeeper/Kafka on your local machine to run following tests.
If running on Mac and java 1.7 for ZooKeeper/Kafka, run following command before starting Kafka:
echo "127.0.0.1 $HOSTNAME" | sudo tee -a /etc/hosts
package integration
import (
	"github.com/Shopify/sarama"
	"github.com/bsm/sarama-cluster"
	"github.com/pborman/uuid"
	"log"
	"time"
)