forked from itspage/go-platform
/
stream.go
41 lines (32 loc) · 793 Bytes
/
stream.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"fmt"
"github.com/micro/go-micro/client"
"github.com/micro/go-micro/cmd"
proto "github.com/micro/router-srv/proto/router"
"golang.org/x/net/context"
)
var (
service = "go.micro.srv.router"
)
func main() {
cmd.Init()
r := proto.NewRouterClient(service, client.DefaultClient)
stream, err := r.SelectStream(context.TODO(), &proto.SelectRequest{Service: service})
if err != nil {
fmt.Println("error streaming", err)
return
}
for i := 0; i <= 3; {
fmt.Println("waiting on stream")
rsp, err := stream.Recv()
if err != nil {
fmt.Println("error receiving", err)
return
}
fmt.Println("got stream response, expires", rsp.Expires)
for _, s := range rsp.Services {
fmt.Printf("received %s %s %+v\n", s.Name, s.Version, s.Nodes)
}
}
}