Created
November 7, 2016 18:51
-
-
Save anxiousmodernman/73f425ea850918403473f8046299ca7d to your computer and use it in GitHub Desktop.
ZK connection keepalive demonstartion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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