private async Task <string> GetConfigInner(string tenant, string dataId, string group, long timeoutMs) { group = ParamUtils.Null2DefaultGroup(group); ParamUtils.CheckKeyParam(dataId, group); ConfigResponse cr = new ConfigResponse(); cr.SetDataId(dataId); cr.SetTenant(tenant); cr.SetGroup(group); // 优先使用本地配置 string content = await FileLocalConfigInfoProcessor.GetFailoverAsync(_worker.GetAgentName(), dataId, group, tenant); if (content != null) { _logger?.LogWarning( "[{0}] [get-config] get failover ok, dataId={1}, group={2}, tenant={3}, config={4}", _worker.GetAgentName(), dataId, group, tenant, ContentUtils.TruncateContent(content)); cr.SetContent(content); _configFilterChainManager.DoFilter(null, cr); content = cr.GetContent(); return(content); } try { List <string> ct = await _worker.GetServerConfig(dataId, group, tenant, timeoutMs, false); cr.SetContent(ct[0]); _configFilterChainManager.DoFilter(null, cr); content = cr.GetContent(); return(content); } catch (NacosException ioe) { if (NacosException.NO_RIGHT == ioe.ErrorCode) { throw; } _logger?.LogWarning( "[{0}] [get-config] get from server error, dataId={1}, group={2}, tenant={3}, msg={4}", _worker.GetAgentName(), dataId, group, tenant, ioe.ErrorMsg); } _logger?.LogWarning( "[{0}] [get-config] get snapshot ok, dataId={1}, group={2}, tenant={3}, config={4}", _worker.GetAgentName(), dataId, group, tenant, ContentUtils.TruncateContent(content)); content = await FileLocalConfigInfoProcessor.GetSnapshotAync(_worker.GetAgentName(), dataId, group, tenant); cr.SetContent(content); _configFilterChainManager.DoFilter(null, cr); content = cr.GetContent(); return(content); }
public async Task <string> GetConfig(string dataId, string group) { if (string.IsNullOrEmpty(dataId)) { throw new ArgumentNullException(nameof(dataId)); } group = Null2DefaultGroup(group); ConfigResponse cr = new ConfigResponse(); cr.DataId = dataId; cr.Tenant = _namespace; cr.Group = group; // 先使用本地缓存 string content = _localConfigInfoProcessor.GetFailover(_agent.GetName(), dataId, group, _namespace); if (!string.IsNullOrEmpty(content)) { _logger.Warn($"[{_agent.GetName()}] [get-config] get failover ok, dataId={dataId}, group={group}, tenant={_namespace}, config={ContentUtils.TruncateContent(content)}"); cr.Content = content; _configFilterChainManager.DoFilter(null, cr); content = cr.Content; return(content); } try { content = await _worker.GetServerConfig(dataId, group, _namespace); cr.Content = content; _configFilterChainManager.DoFilter(null, cr); content = cr.Content; return(content); } catch (Exception ex) { _logger.Warn(ex, $"[{_agent.GetName()}] [get-config] get from server error, dataId={dataId}, group={group}, tenant={_namespace}"); } _logger.Warn($"[{_agent.GetName()}] [get-config] get snapshot ok, dataId={dataId}, tenant={_namespace}, config={ContentUtils.TruncateContent(content)}"); content = _localConfigInfoProcessor.GetSnapshot(_agent.GetName(), dataId, group, _namespace); cr.Content = content; _configFilterChainManager.DoFilter(null, cr); content = cr.Content; return(content); }
private void SafeNotifyListener(string dataId, string group, string content, string md5, ManagerListenerWrap listenerWrap) { // 此处为异步,当前为同步实现 ConfigResponse cr = new ConfigResponse(); cr.DataId = DataId; cr.Group = group; cr.Content = content; _configFilterChainManager.DoFilter(null, cr); listenerWrap.Listener(cr.Content); listenerWrap.LastCallMD5 = md5; _logger.Info($"[{_name}] [notify-ok] dataId={dataId}, group={group}, md5={md5}"); }
private void SafeNotifyListener(string dataId, string group, string content, string type, string md5, string encryptedDataKey, ManagerListenerWrap wrap) { var listener = wrap.Listener; ConfigResponse cr = new ConfigResponse(); cr.SetDataId(dataId); cr.SetGroup(group); cr.SetContent(content); cr.SetEncryptedDataKey(encryptedDataKey); ConfigFilterChainManager.DoFilter(null, cr); // after filter, such as decrypted value string contentTmp = cr.GetContent(); wrap.LastContent = content; wrap.LastCallMd5 = md5; // should pass the value after filter listener.ReceiveConfigInfo(contentTmp); }