private static void BuildService(string name, MicroServiceAttribute microServiceAttribute) { var port = 0; if (microServiceAttribute.Port != 0) { port = microServiceAttribute.Port; } else { port = GetPort(name); } var ip = GetIpAddress(); Server server = new Server { Services = { ApolloService.BindService(new ApolloServiceImpl()) }, Ports = { new ServerPort("", port, ServerCredentials.Insecure) } }; server.Start(); var consulRegist = new AgentServiceRegistration { ID = name + Guid.NewGuid(), Name = name, Port = port, Address = ip, Tags = new string[] { Environment.MachineName, ".net core" }, Check = new AgentServiceCheck { TCP = GetIpAddress() + ":" + ConsulHelper.HealthPort, Interval = new TimeSpan(0, 0, 5), Timeout = new TimeSpan(0, 0, 5) } }; ConsulHelper.Registor(consulRegist); }