protected override async Task <ConfigResponse> QueryConfig(string dataId, string group, string tenant, long readTimeous, bool notify) { try { var request = new ConfigQueryRequest(dataId, group, tenant); request.PutHeader("notify", notify.ToString()); var response = (ConfigQueryResponse) await RequestProxy(GetOneRunningClient(), request).ConfigureAwait(false); ConfigResponse configResponse = new ConfigResponse(); if (response.IsSuccess()) { await FileLocalConfigInfoProcessor.SaveSnapshotAsync(this.GetName(), dataId, group, tenant, response.Content).ConfigureAwait(false); configResponse.SetContent(response.Content); configResponse.SetConfigType(response.ContentType.IsNotNullOrWhiteSpace() ? response.ContentType : "text"); string encryptedDataKey = response.EncryptedDataKey; await FileLocalConfigInfoProcessor.SaveEncryptDataKeySnapshot(this.GetName(), dataId, group, tenant, encryptedDataKey).ConfigureAwait(false); configResponse.SetEncryptedDataKey(encryptedDataKey); return(configResponse); } else if (response.ErrorCode.Equals(ConfigQueryResponse.CONFIG_NOT_FOUND)) { await FileLocalConfigInfoProcessor.SaveSnapshotAsync(this.GetName(), dataId, group, tenant, null).ConfigureAwait(false); await FileLocalConfigInfoProcessor.SaveEncryptDataKeySnapshot(this.GetName(), dataId, group, tenant, null).ConfigureAwait(false); return(configResponse); } else if (response.ErrorCode.Equals(ConfigQueryResponse.CONFIG_QUERY_CONFLICT)) { _logger?.LogError( "[{0}] [sub-server-error] get server config being modified concurrently, dataId={1}, group={2}, tenant={3}", GetName(), dataId, group, tenant); throw new NacosException(NacosException.CONFLICT, $"data being modified, dataId={dataId},group={group},tenant={tenant}"); } else { _logger?.LogError( "[{0}] [sub-server-error] dataId={1}, group={2}, tenant={3}, code={4}", GetName(), dataId, group, tenant, response.ToJsonString()); throw new NacosException(response.ErrorCode, $"http error, code={response.ErrorCode}, dataId={dataId},group={group},tenant={tenant}"); } } catch (Exception ex) { _logger?.LogError(ex, "[{0}] [sub-server-error] dataId={1}, group={2}, tenant={3}, code={4} ", GetName(), dataId, group, tenant, ex.Message); throw; } }
protected override async Task <ConfigResponse> QueryConfig(string dataId, string group, string tenant, long readTimeous, bool notify) { try { var request = new ConfigQueryRequest(dataId, group, tenant); request.PutHeader(ConfigConstants.NOTIFY_HEADER, notify.ToString()); var rpcClient = GetOneRunningClient(); if (notify) { var key = GroupKey.GetKeyTenant(dataId, group, tenant); if (_cacheMap.TryGetValue(key, out var cacheData)) { rpcClient = EnsureRpcClient(cacheData.TaskId.ToString()); } } var response = (ConfigQueryResponse) await RequestProxy(rpcClient, request).ConfigureAwait(false); ConfigResponse configResponse = new ConfigResponse(); if (response.IsSuccess()) { await FileLocalConfigInfoProcessor.SaveSnapshotAsync(this.GetName(), dataId, group, tenant, response.Content).ConfigureAwait(false); configResponse.SetContent(response.Content); configResponse.SetConfigType(response.ContentType.IsNotNullOrWhiteSpace() ? response.ContentType : "text"); // in nacos 2.0.2 still do not return the EncryptedDataKey // so this always be null at this time!!! string encryptedDataKey = response.EncryptedDataKey; await FileLocalConfigInfoProcessor.SaveEncryptDataKeySnapshot(this.GetName(), dataId, group, tenant, encryptedDataKey).ConfigureAwait(false); configResponse.SetEncryptedDataKey(encryptedDataKey); return(configResponse); } else if (response.ErrorCode.Equals(ConfigQueryResponse.CONFIG_NOT_FOUND)) { await FileLocalConfigInfoProcessor.SaveSnapshotAsync(this.GetName(), dataId, group, tenant, null).ConfigureAwait(false); await FileLocalConfigInfoProcessor.SaveEncryptDataKeySnapshot(this.GetName(), dataId, group, tenant, null).ConfigureAwait(false); return(configResponse); } else if (response.ErrorCode.Equals(ConfigQueryResponse.CONFIG_QUERY_CONFLICT)) { _logger?.LogError( "[{0}] [sub-server-error] get server config being modified concurrently, dataId={1}, group={2}, tenant={3}", GetName(), dataId, group, tenant); throw new NacosException(NacosException.CONFLICT, $"data being modified, dataId={dataId},group={group},tenant={tenant}"); } else { _logger?.LogError( "[{0}] [sub-server-error] dataId={1}, group={2}, tenant={3}, code={4}", GetName(), dataId, group, tenant, response.ToJsonString()); throw new NacosException(response.ErrorCode, $"http error, code={response.ErrorCode}, dataId={dataId},group={group},tenant={tenant}"); } } catch (Exception ex) { _logger?.LogError(ex, "[{0}] [sub-server-error] dataId={1}, group={2}, tenant={3}, code={4} ", GetName(), dataId, group, tenant, ex.Message); throw; } }