public async Task StartAsync(string name, string address, int port, CancellationToken token = default(CancellationToken)) { _host.Start(); var builder = new UriBuilder("http", _consulAddress, _consulPort); _serviceDiscovery = new ServiceDiscovery(builder.Uri, _datacenter); if (IPAddress.TryParse(address, out var ip)) { _serviceId = await _serviceDiscovery.RegisterServiceAsync(name, new IPEndPoint(ip, port), token) .ConfigureAwait(false); } else { _serviceId = await _serviceDiscovery.RegisterServiceAsync(name, new DnsEndPoint(address, port), token) .ConfigureAwait(false); } }
private static async Task RunAsync(this IGrpcHost host, CancellationToken token, string shutdownMessage) { using (host) { host.Start(); var hostingEnvironment = host.Services.GetService <IHostingEnvironment>(); Console.WriteLine($"Hosting environment: {hostingEnvironment.EnvironmentName}"); Console.WriteLine($"Content root path: {hostingEnvironment.ContentRootPath}"); foreach (var port in host.Server.Ports) { Console.WriteLine($"Now listening on: {port.Host}:{port.Port}"); } if (!string.IsNullOrEmpty(shutdownMessage)) { Console.WriteLine(shutdownMessage); } await host.WaitForTokenShutdownAsync(token); } }