public static async Task<Channel> GetChannelAsync(string serviceName) { string hostName = serviceName; if (!string.IsNullOrEmpty(hostName)) { if (hostName[0] == '@') { GrpcService service = await _locator.Locate(hostName.Substring(1), ChannelCredentials.Insecure); return await service.Connect(TimeSpan.FromSeconds(2)); } var uri = new Uri(hostName); var channel = new Channel(uri.Host, uri.Port, ChannelCredentials.Insecure); //await channel.ConnectAsync(DateTime.UtcNow.AddSeconds(15)); return channel; } throw new ArgumentException($"Service name does not appear in the configuration: {serviceName}", nameof(serviceName)); }
public async Task GrpcService_A_Test() { var locator = new GrpcLocator { NoCache = true, Randomize = true }; Console.WriteLine("Testing in {0}", locator.ServiceDomain); GrpcService svc = await locator.Locate("onumbers", ChannelCredentials.Insecure); Assert.IsNotNull(svc); Assert.IsTrue(svc.Endpoints.Count > 0); // for testing - remove servers 4/5 //svc.Endpoints.Remove(svc.Endpoints.First(ep => ep.Host == "vsrcoredock04.ipzhost.net")); //svc.Endpoints.Remove(svc.Endpoints.First(ep => ep.Host == "vsrcoredock05.ipzhost.net")); foreach (GrpcEndpoint ep in svc.Endpoints) { Console.WriteLine(ep); } Assert.IsTrue(svc.Expires < DateTime.UtcNow.AddMinutes(15)); Console.WriteLine(); int ts = Environment.TickCount; //TimeSpan tryNextAfter = Timeout.InfiniteTimeSpan; TimeSpan tryNextAfter = TimeSpan.FromMilliseconds(150); var channel = svc.Connect(TimeSpan.FromSeconds(3), tryNextAfter).Result; Assert.IsTrue(channel.State == ChannelState.Ready); Console.WriteLine("Connected To: '{0}' in {1}ms", channel.Target, Environment.TickCount - ts); }