public BeatReactor(ILogger logger, NamingHttpClientProxy serverProxy, NacosSdkOptions options) { this._logger = logger; this._serverProxy = serverProxy; this._dom2Beat = new ConcurrentDictionary <string, BeatInfo>(); this._beatTimer = new ConcurrentDictionary <string, Timer>(); }
public NamingGrpcClientProxy( ILogger logger, string namespaceId, SecurityProxy securityProxy, IServerListFactory serverListFactory, NacosSdkOptions options, ServiceInfoHolder serviceInfoHolder) { this._logger = logger; this.namespaceId = namespaceId; this.uuid = Guid.NewGuid().ToString(); this._options = options; this._securityProxy = securityProxy; this.requestTimeout = options.DefaultTimeOut > 0 ? options.DefaultTimeOut : 3000L; Dictionary <string, string> labels = new Dictionary <string, string>() { { RemoteConstants.LABEL_SOURCE, RemoteConstants.LABEL_SOURCE_SDK }, { RemoteConstants.LABEL_MODULE, RemoteConstants.LABEL_MODULE_NAMING }, }; this.rpcClient = RpcClientFactory.CreateClient(uuid, RemoteConnectionType.GRPC, labels); this.namingGrpcConnectionEventListener = new NamingGrpcConnectionEventListener(_logger, this); Start(serverListFactory, serviceInfoHolder); }
public NamingHttpClientProxy( ILogger logger, string namespaceId, SecurityProxy securityProxy, ServerListManager serverListManager, NacosSdkOptions options, ServiceInfoHolder serviceInfoHolder, IHttpClientFactory clientFactory = null) { this._logger = logger; this._clientFactory = clientFactory; this.serverListManager = serverListManager; this._securityProxy = securityProxy; this._options = options; this.SetServerPort(DEFAULT_SERVER_PORT); this.namespaceId = namespaceId; this.beatReactor = new BeatReactor(_logger, this, _options); // Don't create PushReceiver when using rpc, it will create a udp server if (!options.NamingUseRpc) { this.pushReceiver = new PushReceiver(_logger, serviceInfoHolder, _options); } this.serviceInfoHolder = serviceInfoHolder; }
public ServiceInfoUpdateService(NacosSdkOptions properties, ServiceInfoHolder serviceInfoHolder, INamingClientProxy namingClientProxy, InstancesChangeNotifier changeNotifier) { this.serviceInfoHolder = serviceInfoHolder; this.namingClientProxy = namingClientProxy; this.changeNotifier = changeNotifier; }
public SecurityProxy(IOptionsMonitor <NacosSdkOptions> optionsAccs) { _options = optionsAccs.CurrentValue; _username = _options.UserName ?? ""; _password = _options.Password ?? ""; contextPath = _options.ContextPath; contextPath = contextPath.StartsWith("/") ? contextPath : "/" + contextPath; }
public ServiceInfoUpdateService(ILogger logger, NacosSdkOptions properties, ServiceInfoHolder serviceInfoHolder, INamingClientProxy namingClientProxy, InstancesChangeNotifier changeNotifier) { this._logger = logger; this._timerMap = new ConcurrentDictionary <string, Timer>(); this._serviceInfoHolder = serviceInfoHolder; this._namingClientProxy = namingClientProxy; this._changeNotifier = changeNotifier; }
public SecurityProxy(NacosSdkOptions optionsAccs) { _options = optionsAccs; _username = _options.UserName ?? ""; _password = _options.Password ?? ""; contextPath = _options.ContextPath; contextPath = contextPath.StartsWith("/") ? contextPath : "/" + contextPath; }
public NamingClientProxyDelegate(ILogger logger, string @namespace, ServiceInfoHolder serviceInfoHolder, NacosSdkOptions options, InstancesChangeNotifier changeNotifier) { this._options = options; this.serverListManager = new ServerListManager(logger, options); this.serviceInfoHolder = serviceInfoHolder; this.securityProxy = new SecurityProxy(options, logger); InitSecurityProxy(); this._serviceInfoUpdateService = new ServiceInfoUpdateService(options, serviceInfoHolder, this, changeNotifier); this.grpcClientProxy = new NamingGrpcClientProxy(logger, @namespace, securityProxy, serverListManager, options, serviceInfoHolder); this.httpClientProxy = new NamingHttpClientProxy(logger, @namespace, securityProxy, serverListManager, options, serviceInfoHolder); }
public NacosNamingService( ILoggerFactory loggerFactory, IOptions <NacosSdkOptions> optionAccs) { _logger = loggerFactory.CreateLogger <NacosNamingService>(); _options = optionAccs.Value; _namespace = _options.Namespace; this._changeNotifier = new InstancesChangeNotifier(); this._serviceInfoHolder = new ServiceInfoHolder(_logger, _namespace, _options, _changeNotifier); this._clientProxy = new NamingClientProxyDelegate(_logger, _namespace, _serviceInfoHolder, _options, _changeNotifier); }
private bool IsLoadCacheAtStart(NacosSdkOptions nacosOptions) { bool loadCacheAtStart = false; if (nacosOptions != null && nacosOptions.NamingLoadCacheAtStart.IsNotNullOrWhiteSpace()) { loadCacheAtStart = Convert.ToBoolean(nacosOptions.NamingLoadCacheAtStart); } return(loadCacheAtStart); }
public PushReceiver(ILogger logger, ServiceInfoHolder serviceInfoHolder, NacosSdkOptions options) { this._logger = logger; this._serviceInfoHolder = serviceInfoHolder; // if using grpc, do not setup a udp client here. if (!options.NamingUseRpc) { Task.Factory.StartNew( async() => await RunAsync(), TaskCreationOptions.LongRunning); } }
public ConfigFilterChainManager(NacosSdkOptions options) { List <IConfigFilter> configFilters = GetAssemblies(options).SelectMany(item => item.GetTypes()) .Where(item => item.GetInterfaces().Contains(typeof(IConfigFilter))) .Select(type => (IConfigFilter)System.Activator.CreateInstance(type)).ToList(); foreach (var configFilter in configFilters) { configFilter.Init(options); AddFilter(configFilter); } }
public void Init(NacosSdkOptions options) { // 从拓展信息里面获取需要加密的 json path // 这里只是示例,根据具体情况调整成自己合适的!!!! var extInfo = JObject.Parse(options.ConfigFilterExtInfo); if (extInfo.ContainsKey("JsonPaths")) { _jsonPaths = extInfo.GetValue("JsonPaths").ToObject <List <string> >(); } Console.WriteLine("Assemblies = " + string.Join(",", options.ConfigFilterAssemblies)); Console.WriteLine("Ext Info = " + string.Join(",", options.ConfigFilterExtInfo)); Console.WriteLine("Init"); }
public ConfigRpcTransportClient( ILogger logger, NacosSdkOptions options, ServerListManager serverListManager, ConcurrentDictionary <string, CacheData> cacheMap) { this._logger = logger; this._options = options; this._serverListManager = serverListManager; this._accessKey = _options.AccessKey; this._secretKey = _options.SecretKey; this._cacheMap = cacheMap; this._securityProxy = new Security.SecurityProxy(options); StartInner(); }
public ConfigHttpTransportClient( ILogger logger, NacosSdkOptions options, ServerListManager serverListManager, ConcurrentDictionary <string, CacheData> cacheMap) { this._logger = logger; this._options = options; this._serverListManager = serverListManager; this._cacheMap = cacheMap; this._securityProxy = new Security.SecurityProxy(options, logger); Init(); _agent = new ServerHttpAgent(_logger, options); StartInner(); }
public ServiceInfoHolder(ILogger logger, string @namespace, NacosSdkOptions nacosOptions, InstancesChangeNotifier notifier = null) { this._logger = logger; this._notifier = notifier; InitCacheDir(@namespace); if (IsLoadCacheAtStart(nacosOptions)) { var data = DiskCache.ReadAsync(this.cacheDir).ConfigureAwait(false).GetAwaiter().GetResult(); this.serviceInfoMap = new ConcurrentDictionary <string, Dtos.ServiceInfo>(data); } else { this.serviceInfoMap = new ConcurrentDictionary <string, Dtos.ServiceInfo>(); } this.failoverReactor = new FailoverReactor(this, cacheDir); }
private void InitCacheDir(string @namespace, NacosSdkOptions options) { var jmSnapshotPath = EnvUtil.GetEnvValue("JM.SNAPSHOT.PATH"); string namingCacheRegistryDir = string.Empty; if (options.NamingCacheRegistryDir.IsNotNullOrWhiteSpace()) { namingCacheRegistryDir = options.NamingCacheRegistryDir; } if (!string.IsNullOrWhiteSpace(jmSnapshotPath)) { cacheDir = Path.Combine(jmSnapshotPath, FILE_PATH_NACOS, FILE_PATH_NAMING, @namespace); } else { cacheDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), FILE_PATH_NACOS, FILE_PATH_NAMING, @namespace); } }
private List <Assembly> GetAssemblies(NacosSdkOptions options) { var assemblies = new List <Assembly>(); if (options.ConfigFilterAssemblies == null || !options.ConfigFilterAssemblies.Any()) { return(assemblies); } DependencyContext context = DependencyContext.Default; var libs = context.CompileLibraries.Where(lib => options.ConfigFilterAssemblies.Contains(lib.Name)); foreach (var lib in libs) { var assembly = Assembly.Load(new AssemblyName(lib.Name)); assemblies.Add(assembly); } return(assemblies); }
private void InitServerAddr(NacosSdkOptions options) { this._endpoint = options.EndPoint; if (!string.IsNullOrWhiteSpace(_endpoint)) { this._serversFromEndpoint = GetServerListFromEndpoint() .ConfigureAwait(false).GetAwaiter().GetResult(); this._refreshServerListTimer = new Timer( async x => { await RefreshSrvIfNeedAsync(); }, null, 0, _refreshServerListInternal); } else { var serverlist = options.ServerAddresses; this._serverList.AddRange(serverlist); if (this._serverList.Count == 1) { this._nacosDomain = serverlist[0]; } } }
public BeatReactor(ILogger logger, NamingHttpClientProxy serverProxy, NacosSdkOptions options) { this._logger = logger; this._serverProxy = serverProxy; }
public ServerListManager(ILogger logger, NacosSdkOptions options) { this._logger = logger; InitServerAddr(options); }
public void Init(NacosSdkOptions options) { Console.WriteLine("Assemblies = " + string.Join(",", options.ConfigFilterAssemblies)); Console.WriteLine("Ext Info = " + string.Join(",", options.ConfigFilterExtInfo)); Console.WriteLine("Init"); }
public ServerListManager(ILogger logger, NacosSdkOptions options, string @namespace) { this._logger = logger; this._namespace = @namespace; InitServerAddr(options); }
public ServerHttpAgent(ILogger logger, NacosSdkOptions options) { this._logger = logger; this._serverListMgr = new ServerListManager(logger, options); }
public ClientWorker(ILogger logger, ConfigFilterChainManager configFilterChainManager, NacosSdkOptions options) { _logger = logger; _configFilterChainManager = configFilterChainManager; ServerListManager serverListManager = new ServerListManager(logger, options); _agent = options.ConfigUseRpc ? new ConfigRpcTransportClient(logger, options, serverListManager, _cacheMap) : new ConfigHttpTransportClient(logger, options, serverListManager, _cacheMap); }
public ServerListManager(ILogger logger, NacosSdkOptions options) { _logger = logger; _options = options; _serverUrls = new List <string>(); _contentPath = _options.ContextPath; _defaultNodesPath = DefaultNodesPath; var @namespace = _options.Namespace; if (_options.ServerAddresses != null && _options.ServerAddresses.Any()) { _isFixed = true; foreach (var item in _options.ServerAddresses) { // here only trust the input server addresses of user _serverUrls.Add(item.TrimEnd('/')); } if (@namespace.IsNullOrWhiteSpace()) { _name = $"{FIXED_NAME}-{GetFixedNameSuffix(_serverUrls)}"; } else { _namespace = @namespace; _tenant = @namespace; _name = $"{FIXED_NAME}-{GetFixedNameSuffix(_serverUrls)}-{@namespace}"; } } else { if (_options.EndPoint.IsNullOrWhiteSpace()) { throw new NacosException(NacosException.CLIENT_INVALID_PARAM, "endpoint is blank"); } _isFixed = false; if (@namespace.IsNullOrWhiteSpace()) { _name = _options.EndPoint; _addressServerUrl = $"http://{_options.EndPoint}:{_endpointPort}/{_contentPath}/{_defaultNodesPath}"; } else { _namespace = @namespace; _tenant = $"{_options.EndPoint}-{@namespace}"; _name = $"{FIXED_NAME}-{GetFixedNameSuffix(_serverUrls)}-{@namespace}"; _addressServerUrl = $"http://{_options.EndPoint}:{_endpointPort}/{_contentPath}/{_defaultNodesPath}?namespace={@namespace}"; } _refreshSvcListTimer = new Timer( async x => { await RefreshSrvAsync().ConfigureAwait(false); }, null, TimeSpan.Zero, TimeSpan.FromSeconds(10)); RefreshSrvAsync().ConfigureAwait(false).GetAwaiter().GetResult(); } }