private void RedoRegisterEachService() { foreach (var item in _registeredInstanceCached) { var serviceName = NamingUtils.GetServiceName(item.Key); var groupName = NamingUtils.GetGroupName(item.Key); RedoRegisterEachInstance(serviceName, groupName, item.Value); } }
private void RedoRegisterEachService() { _logger?.LogInformation("Grpc re-connect, redo register services"); foreach (var item in _registeredInstanceCached) { var serviceName = NamingUtils.GetServiceName(item.Key); var groupName = NamingUtils.GetGroupName(item.Key); RedoRegisterEachInstance(serviceName, groupName, item.Value); } }
private async Task BeatTask(BeatInfo beatInfo) { if (beatInfo.Stopped) { return; } long nextTime = beatInfo.Period; try { Newtonsoft.Json.Linq.JObject result = await _serverProxy.SendBeat(beatInfo, false); long interval = result.GetValue("clientBeatInterval").ToObject <long>(); bool lightBeatEnabled = false; if (result.ContainsKey(CommonParams.LIGHT_BEAT_ENABLED)) { lightBeatEnabled = result.GetValue(CommonParams.LIGHT_BEAT_ENABLED).ToObject <bool>(); } if (interval > 0) { nextTime = interval; } int code = 10200; if (result.ContainsKey(CommonParams.CODE)) { code = result.GetValue(CommonParams.CODE).ToObject <int>(); } if (code == 20404) { Instance instance = new Instance { Port = beatInfo.Port, Ip = beatInfo.Ip, Weight = beatInfo.Weight ?? 1, Metadata = beatInfo.Metadata, ClusterName = beatInfo.Cluster, ServiceName = beatInfo.ServiceName, Ephemeral = true, // InstanceId = "" }; try { await _serverProxy.RegisterServiceAsync(beatInfo.ServiceName, NamingUtils.GetGroupName(beatInfo.ServiceName), instance); } catch { } } } catch (NacosException ex) { _logger?.LogError(ex, "[CLIENT-BEAT] failed to send beat: {0}, code: {1}, msg: {2}", beatInfo, ex.ErrorCode, ex.ErrorMsg); } string key = BuildKey(beatInfo.ServiceName, beatInfo.Ip, beatInfo.Port); if (_beatTimer.TryGetValue(key, out var timer)) { timer.Change(nextTime, Timeout.Infinite); } }