protected override void StartService() { logger.Info("配置管理服务开始"); this.ServiceName = "配置管理服务"; this._configInfo = ConfigManager.GetConfigInfo(); if (string.IsNullOrEmpty(this._configInfo.ConfigName)) { throw new ConfigInitException("配置标识不能为空"); } if (string.IsNullOrEmpty(this._configInfo.RemoteConfigServerAddress)) { throw new ConfigInitException("配置服务地址不能为空"); } this._client = new IkZooKeeperClient(this._configInfo.RemoteConfigServerAddress, TimeSpan.FromSeconds(15), this); logger.Info(string.Format("配置管理服务开始完成,配置标识:{0},配置版本:{1},配置服务地址:{2}", this._configInfo.ConfigName, this._configInfo.VersionInfo, this._configInfo.RemoteConfigServerAddress)); }
protected override void StartService() { int port = ConfigManager.Instance.Get <int>("event_listener_port"); if (port > 0) { this._port = port; } int heartbeatCheckMilliseconds = ConfigManager.Instance.Get <int>("event_heartbeat_check"); if (heartbeatCheckMilliseconds > 0) { this._heartbeatCheckMilliseconds = heartbeatCheckMilliseconds; } string eventServerAddress = ConfigManager.Instance.Get <string>("event_server_address"); if (string.IsNullOrEmpty(eventServerAddress)) { throw new EventException("事件服务地址不能为空"); } this._eventServerAddress = eventServerAddress; this._client = new IkZooKeeperClient(eventServerAddress, TimeSpan.FromSeconds(15), null); _logger.Info(string.Format("开始分布式事件订阅服务,监听端口:{0},心跳检查时间:{1},事件服务地址:{2}", this._port, this._heartbeatCheckMilliseconds, eventServerAddress)); Task.Run(() => { foreach (var item in sourceArrays.GetConsumingEnumerable()) { if (item.ClearType == ClearType.Address) { var publisher = GetEventPublisher(item.Topic, item.Address); bool flag = false; try { publisher.EventPublisher.Heartbeat(); flag = true; break; } catch { } if (!flag) { var path = BuildZooKeeperPath(item.Topic, item.Address); try { if (_client.EnsureExists(path, false)) { _client.EnsureDelete(path); } if (!RemoveEventPublisher(item.Topic, item.Address)) { _logger.Error(string.Format("清理通信通道错误,主题:{0},地址:{1}", item.Topic, item.Address)); } } catch (Exception ex) { _logger.Error(string.Format("清理消费错误,主题:{0},地址:{1}", item.Topic, item.Address), ex); } } } else { var path = BuildZooKeeperPath(item.Topic); try { if (_client.EnsureExists(path, false)) { _client.EnsureDelete(path); } } catch (Exception ex) { _logger.Error(string.Format("清理消费错误,主题:{0}", item.Topic), ex); } } } }); CheckTopicServerHeartbeat(); EnsureSubscribe(); var worker = AddWorkerThread(); worker.Start(); }