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

Function main

examples/features/debugging/client/main.go:48–93  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

46)
47
48func main() {
49 flag.Parse()
50 /***** Set up the server serving channelz service. *****/
51 lis, err := net.Listen("tcp", *addr)
52 if err != nil {
53 log.Fatalf("failed to listen: %v", err)
54 }
55 defer lis.Close()
56 s := grpc.NewServer()
57 service.RegisterChannelzServiceToServer(s)
58 go s.Serve(lis)
59 defer s.Stop()
60
61 /***** Initialize manual resolver and Dial *****/
62 r := manual.NewBuilderWithScheme("whatever")
63 r.InitialState(resolver.State{Addresses: []resolver.Address{{Addr: ":10001"}, {Addr: ":10002"}, {Addr: ":10003"}}})
64 // Set up a connection to the server.
65 conn, err := grpc.NewClient(r.Scheme()+":///test.server", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(r), grpc.WithDefaultServiceConfig(`{"loadBalancingPolicy":"round_robin"}`))
66 if err != nil {
67 log.Fatalf("did not connect: %v", err)
68 }
69 defer conn.Close()
70 // Manually provide resolved addresses for the target.
71
72 c := pb.NewGreeterClient(conn)
73
74 // Contact the server and print out its response.
75
76 /***** Make 100 SayHello RPCs *****/
77 for i := 0; i < 100; i++ {
78 // Setting a 150ms timeout on the RPC.
79 ctx, cancel := context.WithTimeout(context.Background(), 150*time.Millisecond)
80 defer cancel()
81 r, err := c.SayHello(ctx, &pb.HelloRequest{Name: *name})
82 if err != nil {
83 log.Printf("could not greet: %v", err)
84 } else {
85 log.Printf("Greeting: %s", r.Message)
86 }
87 }
88
89 /***** Wait for user exiting the program *****/
90 // Unless you exit the program (e.g. CTRL+C), channelz data will be available for querying.
91 // Users can take time to examine and learn about the info provided by channelz.
92 select {}
93}

Callers

nothing calls this directly

Calls 15

ServeMethod · 0.95
StopMethod · 0.95
SayHelloMethod · 0.95
NewServerFunction · 0.92
NewBuilderWithSchemeFunction · 0.92
NewClientFunction · 0.92
WithTransportCredentialsFunction · 0.92
NewCredentialsFunction · 0.92
WithResolversFunction · 0.92
WithDefaultServiceConfigFunction · 0.92
InitialStateMethod · 0.80

Tested by

no test coverage detected