1
0
mirror of https://github.com/chai2010/advanced-go-programming-book.git synced 2025-05-27 23:12:20 +00:00
2018-08-10 07:15:11 +08:00

37 lines
587 B
Go

package main
import (
"google.golang.org/grpc"
"log"
."gobook.examples/ch4-04-grpc/grpc-pubsub/helloservice"
"context"
"io"
"fmt"
)
func main() {
conn, err := grpc.Dial("localhost:1234", grpc.WithInsecure())
if err != nil {
log.Fatal(err)
}
defer conn.Close()
client := NewPubsubServiceClient(conn)
stream, err := client.Subscribe(context.Background(), &String{Value: "golang:"})
if err != nil {
log.Fatal(err)
}
for {
reply, err := stream.Recv()
if err != nil {
if err == io.EOF {
break
}
log.Fatal(err)
}
fmt.Println(reply.GetValue())
}
}