MCPcopy
hub / github.com/grpc/grpc-go / main

Function main

examples/features/orca/client/main.go:43–75  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

41var test = flag.Bool("test", false, "if set, only 1 RPC is performed before exiting")
42
43func main() {
44 flag.Parse()
45
46 // Set up a connection to the server. Configure to use our custom LB
47 // policy which will receive all the ORCA load reports.
48 conn, err := grpc.NewClient(*addr,
49 grpc.WithTransportCredentials(insecure.NewCredentials()),
50 grpc.WithDefaultServiceConfig(`{"loadBalancingConfig": [{"orca_example":{}}]}`),
51 )
52 if err != nil {
53 log.Fatalf("did not connect: %v", err)
54 }
55 defer conn.Close()
56
57 c := pb.NewEchoClient(conn)
58
59 // Perform RPCs once per second.
60 ticker := time.NewTicker(time.Second)
61 for range ticker.C {
62 func() {
63 // Use an anonymous function to ensure context cancellation via defer.
64 ctx, cancel := context.WithTimeout(context.Background(), time.Second)
65 defer cancel()
66 if _, err := c.UnaryEcho(ctx, &pb.EchoRequest{Message: "test echo message"}); err != nil {
67 log.Fatalf("Error from UnaryEcho call: %v", err)
68 }
69 }()
70 if *test {
71 return
72 }
73 }
74
75}
76
77// Register an ORCA load balancing policy to receive per-call metrics and
78// out-of-band metrics.

Callers

nothing calls this directly

Calls 8

UnaryEchoMethod · 0.95
NewClientFunction · 0.92
WithTransportCredentialsFunction · 0.92
NewCredentialsFunction · 0.92
WithDefaultServiceConfigFunction · 0.92
ParseMethod · 0.65
FatalfMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected