public async Task GetDataAsyncTest() { var data = await _client.GetDataAsync("/"); Assert.NotNull(data); data = await _client.GetDataAsync("/chanelInfo"); Assert.NotNull(data); }
public async Task CreateTest() { var path = $"/{Guid.NewGuid():N}"; if (await _client.ExistsAsync(path)) { await _client.DeleteAsync(path); } await _client.CreateEphemeralAsync(path, System.Text.Encoding.UTF8.GetBytes("abc")); var data = (await _client.GetDataAsync(path)).ToArray(); Assert.Equal("abc", System.Text.Encoding.UTF8.GetString(data)); await _client.DeleteAsync(path); }
private async Task AddItem(string path) { var data = await _client.GetDataAsync(path); if (data.Any()) { var key = path.Substring(1).Replace("/", ":"); var value = data.Any() ? Encoding.UTF8.GetString(data.ToArray()) : string.Empty; Data[key] = value; } }
private async Task <bool> SetRouteAsync(ServiceRouteDescriptor route, IZookeeperClient zooKeeperClient) { try { bool isSetRoute = false; _logger.LogDebug($"准备添加{route.ServiceDescriptor.Id}服务路由。"); var zooKeeperClients = await _zookeeperClientProvider.GetZooKeeperClients(); await CreateSubdirectory(zooKeeperClient, _configInfo.RoutePath); var path = _configInfo.RoutePath; if (!path.EndsWith("/")) { path += "/"; } var nodePath = $"{path}{route.ServiceDescriptor.Id}"; var nodeData = _serializer.Serialize(route); _logger.LogDebug($"服务路由内容为:{Encoding.UTF8.GetString(nodeData)}。"); if (!nodeWatchers.ContainsKey(nodePath)) { var watcher = nodeWatchers.GetOrAdd(nodePath, f => new NodeMonitorWatcher(path, async(oldData, newData) => await NodeChange(oldData, newData))); await zooKeeperClient.SubscribeDataChange(nodePath, watcher.HandleNodeDataChange); } if (!await zooKeeperClient.ExistsAsync(nodePath)) { _logger.LogDebug($"节点:{nodePath}不存在将进行创建。"); await zooKeeperClient.CreateAsync(nodePath, nodeData, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); } else { var onlineData = (await zooKeeperClient.GetDataAsync(nodePath)).ToArray(); if (!DataEquals(nodeData, onlineData)) { await zooKeeperClient.SetDataAsync(nodePath, nodeData); _logger.LogDebug($"{nodePath}节点的缓存的服务路由与服务注册中心不一致,路由数据已被更新。"); isSetRoute = true; } } return(isSetRoute); } catch (Exception ex) { _logger.LogError($"{route.ServiceDescriptor.Id}服务的路由注册失败,原因:{ex.Message}"); return(false); } }
private ServicePublishInfo GetServicePublishInfo(string path) { var data = client.GetDataAsync(path).Result.ToArray(); return(MessagePackSerializer.Deserialize <ServicePublishInfo>(data)); }
public async Task GetDataAsyncTest() { var data = await _client.GetDataAsync("/"); data = await _client.GetDataAsync("/chanelInfo"); }