Ejemplo n.º 1
0
        public IList <KeyValueInfo <string, string> > Get()
        {
            var list = new List <KeyValueInfo <string, string> >();
            var req  = new HelloRequest();

            for (var i = 0; i < 100; i++)
            {
                var kv = new KeyValueInfo <string, string>();
                req.Name = "黄华英" + i;
                try
                {
                    GRpcChannelUtil.GetGRpcClientFormStrategy <GreeterClient>("GRpcServiceExampleA", (channel) =>
                    {
                        kv.Key = channel.Target;
                        return(new GreeterClient(channel));
                    }, (client, header) =>
                    {
                        var res  = client.SayHello(req);
                        kv.Value = res.Message;
                    });
                }
                catch (Exception ex)
                {
                    kv.Value = ex.Message;
                }
                list.Add(kv);

                Console.WriteLine($"{DateTime.Now.ToFullFixedDateTime()} 请求后结果:" + kv.ToJsonString());

                Thread.Sleep(1000);
            }

            return(list);
        }