예제 #1
0
        public async Task <IActionResult> Info()
        {
            //{
            //    //加权轮询
            //    var services = new List<string>();
            //    foreach (var service in healthServices)
            //    {
            //        services.AddRange(Enumerable.Repeat(service.IP + ":" + service.Port, service.Weight));
            //    }
            //}

            {
                string targetUrl = $"http://{this._IConsulDispatcher.ChooseAddress("LessonService")}";
                //"http://localhost:8000"
                AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
                using (var channel = GrpcChannel.ForAddress(targetUrl))
                {
                    var client = new ZhaoxiLesson.ZhaoxiLessonClient(channel);

                    Console.WriteLine("***************单次调用************");
                    {
                        var reply = await _lessonClient.FindLessonAsync(new ZhaoxiLessonRequest()
                        {
                            Id = 123
                        });

                        string result = Newtonsoft.Json.JsonConvert.SerializeObject(reply.Lesson);
                        Console.WriteLine($"_lessonClient {Thread.CurrentThread.ManagedThreadId} 服务返回数据1:{result} ");
                        base.ViewBag.Result = result;
                    }
                }
            }

            return(View());
        }
예제 #2
0
 public HomeController(ILogger <HomeController> logger
                       , ZhaoxiLesson.ZhaoxiLessonClient lessonClient
                       , IConsulDispatcher consulDispatcher)
 {
     _logger                 = logger;
     this._lessonClient      = lessonClient;
     this._IConsulDispatcher = consulDispatcher;
 }