/// <summary> /// Stops the and deregister. /// </summary> /// <param name="server">The server.</param> /// <param name="stopServer">The stop server.</param> /// <returns></returns> /// <exception cref="Exception">当前服务没有注册,或者是已经被反注册过..</exception> public static async Task <Server> StopAndDeregister(this Grpc.Core.Server server, Action <Server> stopServer = null) { if (!serviceDict.ContainsKey(server.GetHashCode())) { throw new Exception("当前服务没有注册,或者是已经被反注册过.."); } await serviceDict[server.GetHashCode()].Deregister(); serviceDict.Remove(server.GetHashCode()); InnerLogger.Log(LoggerLevel.Info, "反注册服务发现"); if (stopServer == null) { await server.KillAsync(); } else { stopServer(server); } InnerLogger.Log(LoggerLevel.Info, "grpc服务停止"); return(server); }
public void StartAndKillServer() { Server server = new Server { Ports = { new ServerPort("localhost", ServerPort.PickUnused, ServerCredentials.Insecure) } }; server.Start(); server.KillAsync().Wait(); }
public void OnDisable() { Debug.Log("Stopping server"); // shutdown the server try { server.ShutdownAsync().Wait(1000); Debug.Log("Server is stopped."); } catch (Exception e) { Debug.Log("Server did not shutdown in 1s, killing it." + e); server.KillAsync().Wait(); } }
public override void _ExitTree() { GD.Print("Stopping server"); // shutdown the server try { server.ShutdownAsync().Wait(1000); GD.Print("Server is stopped."); } catch (Exception e) { GD.Print("Server did not shutdown in 1s, killing it." + e); server.KillAsync().Wait(); } }