Skip to content

Instantly share code, notes, and snippets.

@anxiousmodernman
Created November 7, 2016 18:51
Show Gist options
  • Save anxiousmodernman/73f425ea850918403473f8046299ca7d to your computer and use it in GitHub Desktop.
Save anxiousmodernman/73f425ea850918403473f8046299ca7d to your computer and use it in GitHub Desktop.
ZK connection keepalive demonstartion
package kafka
import (
"testing"
"time"
"github.com/samuel/go-zookeeper/zk"
)
func TestDiscoverKafka(t *testing.T) {
conn, events, err := zk.Connect([]string{"localhost:2181"}, 5*time.Second)
if err != nil {
t.Errorf("connection error: %v", err)
}
fmt.Println("connection state:", conn.State())
quit := make(chan bool)
go func() {
for e := range events {
fmt.Println("got event type", e.Type)
fmt.Println("got event error", e.Err)
fmt.Println("got event state", e.State)
fmt.Println("got event path", e.Path)
fmt.Println("got event server", e.Server)
}
fmt.Println("quitting")
quit <- true
}()
fmt.Println("initial conn state:", conn.State())
<-quit
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment