/
main.go
46 lines (37 loc) · 1004 Bytes
/
main.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
42
43
44
45
46
package main
import (
"context"
"fmt"
"log"
"time"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
wearablepb "github.com/MarioCarrion/grpc-microservice-example/gen/go/wearable/v1"
)
func main() {
opts := []grpc.DialOption{
grpc.WithTransportCredentials(insecure.NewCredentials()),
}
conn, err := grpc.Dial("localhost:9879", opts...)
if err != nil {
log.Fatalf("fail to dial: %v", err)
}
defer conn.Close()
client := wearablepb.NewWearableServiceClient(conn)
stream, err := client.ConsumeBeatsPerMinute(context.Background())
if err != nil {
log.Fatalln("Consuming stream", err)
}
for i := 0; i < 10; i++ {
err := stream.Send(&wearablepb.ConsumeBeatsPerMinuteRequest{Uuid: "mario", Value: 100, Minute: uint32(i)})
if err != nil {
log.Fatalln("Sending value", err)
}
time.Sleep(100 * time.Millisecond)
}
res, err := stream.CloseAndRecv()
if err != nil {
log.Fatalln("Closing", err)
}
fmt.Println("Total messages", res.GetTotal())
}