internal static ZooKeeperRegisterServiceConfiguration ReadRegisterServiceConfiguration(IConfigurationSection configurationSection) { var service = new ZooKeeperRegisterServiceConfiguration(); var idSection = configurationSection.GetSection("id"); if (idSection.Exists()) { service.Id = idSection.Value; } var nameSection = configurationSection.GetSection("name"); if (nameSection.Exists()) { service.Name = nameSection.Value; } //var hcSection = configurationSection.GetSection("HealthCheckInterval"); //if (hcSection.Exists()) // service.HealthCheckInterval = // TimeSpan.FromMilliseconds(configurationSection.GetValue<int>("HealthCheckInterval")); //service.EnableTagOverride = configurationSection.GetValue<bool>("EnableTagOverride"); //service.Meta = configurationSection.GetValue<Dictionary<string, string>>("meta"); //service.Tags = configurationSection.GetValue<string[]>("tags"); return(service); }
public async Task <bool> RegisterAsync(CancellationToken cancellationToken = default) { if (ZooKeeperRegisterServiceConfiguration == null) { ZooKeeperRegisterServiceConfiguration = new ZooKeeperRegisterServiceConfiguration(); } if (string.IsNullOrWhiteSpace(ZooKeeperRegisterServiceConfiguration.Id)) { ZooKeeperRegisterServiceConfiguration.Id = ServerSettings.ToString(); } if (string.IsNullOrWhiteSpace(ZooKeeperRegisterServiceConfiguration.Name)) { ZooKeeperRegisterServiceConfiguration.Name = ServerSettings.ToString(); } if (string.IsNullOrWhiteSpace(ZooKeeperRegisterServiceConfiguration.Name)) { throw new ArgumentNullException(nameof(ZooKeeperRegisterServiceConfiguration.Name), "Service name value cannot be null."); } try { var data = Codec.Serialize(new ZooKeeperNodeInfo { Weight = ServerSettings.Weight ?? 0, Address = ServerSettings.Address, Port = ServerSettings.Port, EnableTls = ServerSettings.X509Certificate2 != null }); await CreatePath($"{Root}/{ZooKeeperRegisterServiceConfiguration.Name}/{ZooKeeperRegisterServiceConfiguration.Id}", data); return(true); } catch (Exception ex) { Logger.LogError(ex, ex.Message); throw; } }
public static void AddZooKeeper(this IUraganoBuilder builder, ZooKeeperClientConfigure zookeeperClientConfiguration, ZooKeeperRegisterServiceConfiguration zookeeperAgentServiceConfiguration) { builder.AddServiceDiscovery <ZooKeeperServiceDiscovery>(zookeeperClientConfiguration, zookeeperAgentServiceConfiguration); }