Example #1
0
        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);
        }
Example #2
0
        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);
        }