public ClientCallInvoker(IEndpointStrategy strategy, string serviceName, int maxRetry = 0, IClientTracer tracer = null) { _strategy = strategy; _serviceName = serviceName; _maxRetry = maxRetry; _tracer = tracer; }
public void TestRandomness() { IPAddress[] ips = new IPAddress[4]; for (byte i = 0; i < ips.Length; ++i) { ips[i] = new IPAddress(new byte[] { 192, 168, 0, i }); } IEndpointStrategy endpointStrategy = ServiceActivator <Factory> .Create <IEndpointStrategy>("Random", ips.AsEnumerable()); List <IPAddress> alls = new List <IPAddress>(); for (int i = 0; i < 10000; ++i) { IPAddress nextEndpoint = endpointStrategy.Pick(null); if (!alls.Contains(nextEndpoint)) { alls.Add(nextEndpoint); } } foreach (IPAddress ip in alls) { Assert.IsTrue(alls.Contains(ip)); } }
/// <summary> /// /// </summary> /// <param name="loggerWriter"></param> /// <param name="endpointStrategy"></param> /// <param name="serviceDiscovery"></param> public static void Configure(Action <string, Exception> loggerWriter , IEndpointStrategy endpointStrategy , IServiceDiscovery serviceDiscovery) { FormatLogger(loggerWriter); _.EndpointStrategy = endpointStrategy; _.ServiceDiscovery = serviceDiscovery; }
public void TestCreateRandom() { IEndpointStrategy endpointStrategy = ServiceActivator <CassandraSharp.EndpointStrategy.Factory> .Create <IEndpointStrategy>("Random", Enumerable.Empty <IPAddress> (), new SimpleSnitch()); Assert.IsTrue(endpointStrategy is RandomEndpointStrategy); }
public ClientDaemon( IServiceProvider serviceProvider , IServiceDiscovery serviceDiscovery , IEndpointStrategy endpointStrategy) { _serviceProvider = serviceProvider; _serviceDiscovery = serviceDiscovery; _endpointStrategy = endpointStrategy; }
public DefaultCluster(IEndpointStrategy endpointStrategy, ILogger logger, IConnectionFactory connectionFactory, IRecoveryService recoveryService) { _ip2Connection = new Dictionary<IPAddress, IConnection>(); _endpointStrategy = endpointStrategy; _logger = logger; _connectionFactory = connectionFactory; _recoveryService = recoveryService; }
public SingleConnectionPerEndpointCluster(IEndpointStrategy endpointStrategy, ILogger logger, IConnectionFactory connectionFactory, IRecoveryService recoveryService, IPartitioner partitioner) { _ip2Connection = new Dictionary <IPAddress, IConnection>(); _endpointStrategy = endpointStrategy; _logger = logger; _connectionFactory = connectionFactory; _recoveryService = recoveryService; Partitioner = partitioner; }
public ClientCallInvoker( GrpcClientOptions options, IEndpointStrategy strategy, Func <List <ServerCallInvoker>, ServerCallInvoker> callInvokers = default) { _options = options; _strategy = strategy; _callInvokers = callInvokers; }
public SingleConnectionPerEndpointCluster(IEndpointStrategy endpointStrategy, ILogger logger, IConnectionFactory connectionFactory, IRecoveryService recoveryService, IPartitioner partitioner) { _ip2Connection = new Dictionary<IPAddress, IConnection>(); _endpointStrategy = endpointStrategy; _logger = logger; _connectionFactory = connectionFactory; _recoveryService = recoveryService; Partitioner = partitioner; }
public ConnectionPoolEndpointCluster(IEndpointStrategy endpointStrategy, ILogger logger, IConnectionFactory connectionFactory, IRecoveryService recoveryService, IPartitioner partitioner) { _ip2Connection = new ConcurrentDictionary <IPAddress, IConnection[]>(); _endpointStrategy = endpointStrategy; _logger = logger; _connectionFactory = connectionFactory; _recoveryService = recoveryService; Partitioner = partitioner; logger?.Info("ConnectionPoolEndpointCluster created."); }
public ClientCallInvoker(IEndpointStrategy strategy, string serviceName, int maxRetry = 0, IClientTracer tracer = null, List <Interceptor> interceptors = null) { _strategy = strategy; _serviceName = serviceName; _maxRetry = maxRetry; _tracer = tracer; _interceptors = interceptors; if (_tracer != null) { _interceptors = _interceptors ?? new List <Interceptor>(); _interceptors.Add(new ClientTracerInterceptor(_tracer)); } }
public void TestCreateCustom() { string customType = typeof(CustomEndpointStrategy).AssemblyQualifiedName; IEnumerable <IPAddress> endpoints = new List <IPAddress> { null }; IEndpointStrategy endpointStrategy = ServiceActivator <CassandraSharp.EndpointStrategy.Factory> .Create <IEndpointStrategy>(customType, endpoints, new SimpleSnitch()); CustomEndpointStrategy customEndpointStrategy = endpointStrategy as CustomEndpointStrategy; Assert.IsNotNull(customEndpointStrategy); IPAddress customEndpoint = customEndpointStrategy.Endpoints.Single(); Assert.AreEqual(customEndpoint, endpoints.Single()); }
/// <summary> /// 解析配置文件 /// </summary> /// <param name="configFile"></param> /// <returns></returns> private static Exitus ResolveConfiguration(string configFile) { var serviceElement = ResolveServiceConfiguration(configFile); var maxRetry = serviceElement.MaxRetry; var serviceName = serviceElement.Name; var discovery = serviceElement.Discovery; IEndpointStrategy endpointStrategy = default(IEndpointStrategy); if (EnableConsul(discovery, out string address)) { endpointStrategy = ResolveStickyConfiguration(serviceElement, address); } else { endpointStrategy = ResolveEndpointConfiguration(serviceElement); } return(new Exitus(serviceName, maxRetry, endpointStrategy)); }
/// <summary> /// 构造 /// </summary> /// <param name="Services"></param> /// <param name="endpointStrategy"></param> public ClientFactory( #if NETCORE IOptionsMonitor <List <GrpcService> > Services , IEndpointStrategy endpointStrategy #endif ) { _name = $"{typeof(T).DeclaringType.FullName}"; List <GrpcService> services; #if NETCORE services = Services.CurrentValue; _endpointStrategy = endpointStrategy; #else services = GrpcServiceWrapper.Services; _endpointStrategy = CommonUtilsHelper._.EndpointStrategy; #endif _grpcService = services.FirstOrDefault(s => s.Name == _name); }
public ICluster GetCluster(ClusterConfig clusterConfig) { clusterConfig.CheckArgumentNotNull("clusterConfig"); clusterConfig.Endpoints.CheckArgumentNotNull("clusterConfig.Endpoints"); TransportConfig transportConfig = clusterConfig.Transport ?? new TransportConfig(); IRecoveryService recoveryService = GetRecoveryService(transportConfig.Recoverable); KeyspaceConfig keyspaceConfig = clusterConfig.DefaultKeyspace ?? new KeyspaceConfig(); // create endpoints IEndpointSnitch snitch = ServiceActivator <Factory> .Create <IEndpointSnitch>(clusterConfig.Endpoints.Snitch, _logger); IEnumerable <IPAddress> endpoints = clusterConfig.Endpoints.Servers.Select(Network.Find).Where(x => null != x).ToArray(); if (!endpoints.Any()) { throw new ArgumentException("Expecting at least one valid endpoint"); } // create required services IEndpointStrategy endpointsManager = ServiceActivator <EndpointStrategy.Factory> .Create <IEndpointStrategy>(clusterConfig.Endpoints.Strategy, endpoints, snitch, _logger, clusterConfig.Endpoints); IConnectionFactory connectionFactory = ServiceActivator <Transport.Factory> .Create <IConnectionFactory>(transportConfig.Type, transportConfig, keyspaceConfig, _logger, _instrumentation); IPartitioner partitioner = ServiceActivator <Partitioner.Factory> .Create <IPartitioner>(clusterConfig.Partitioner); // create the cluster now ICluster cluster = ServiceActivator <Cluster.Factory> .Create <ICluster>(clusterConfig.Type, endpointsManager, _logger, connectionFactory, recoveryService, partitioner, clusterConfig); IDiscoveryService discoveryService = ServiceActivator <Discovery.Factory> .Create <IDiscoveryService>(clusterConfig.Endpoints.Discovery.Type, clusterConfig.Endpoints.Discovery, _logger, cluster); discoveryService.OnTopologyUpdate += endpointsManager.Update; cluster.OnClosed += discoveryService.SafeDispose; return(cluster); }
public ClientCallInvoker(ServiceRouteDescriptor service, IEndpointStrategy endpointStrategy, int maxRetry = 0) { _service = service; _strategy = endpointStrategy; _maxRetry = maxRetry; }
public ClientDaemon() { _serviceDiscovery = CommonUtilsHelper._.ServiceDiscovery; _endpointStrategy = CommonUtilsHelper._.EndpointStrategy; }
public GrpcClientFactory(IEndpointStrategy endpointStrategy, GrpcClientConfig config) { _endpointStrategy = endpointStrategy; _config = config; }
public ClientFactory(IEndpointStrategy strategy) { _callInvoker = new ClientCallInvoker(strategy, 1); }
/// <summary> /// 构造 /// </summary> /// <param name="endpointStrategy">终端策略</param> /// <param name="serviceName">服务名</param> /// <param name="maxRetry">最大重试次数</param> public ClientCallInvoker(IEndpointStrategy endpointStrategy, string serviceName = "", int maxRetry = 1) { _serviceName = serviceName; _maxRetry = maxRetry; _endpointStrategy = endpointStrategy; }
public ClientCallInvoker(IEndpointStrategy endpointStrategy, int maxRetry = 0) { _endpointStrategy = endpointStrategy; _maxRetry = maxRetry; }
/// <summary> /// 构造函数 /// </summary> /// <param name="serviceName"></param> /// <param name="maxRetry"></param> /// <param name="endpointStrategy"></param> public Exitus(string serviceName, int maxRetry, IEndpointStrategy endpointStrategy) { ServiceName = serviceName; MaxRetry = maxRetry; EndpointStrategy = endpointStrategy; }
/// <summary> /// 构造函数 /// </summary> /// <param name="serviceName"></param> /// <param name="endpointStrategy"></param> public Exitus(string serviceName, IEndpointStrategy endpointStrategy) { ServiceName = serviceName; EndpointStrategy = endpointStrategy; }