internal static Response Call(string serviceKey, string methodKey, params object[] parameters) { var service = ConsulHelper.GetServer(serviceKey); var channel = new Channel(service.Address + ":" + service.Port, ChannelCredentials.Insecure); //System.Console.WriteLine(service.Address + ":" + service.Port); var client = new ApolloService.ApolloServiceClient(channel); var request = new Request(); request.ServiceName = methodKey; var jsonInput = ""; foreach (var arg in parameters) { jsonInput += JsonConvert.SerializeObject(arg) + "兲"; } request.Data = jsonInput; var response = client.Call(request); channel.ShutdownAsync().Wait(); return(response); }
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); }