/** == SniffingConnectionPool * A subclass of StaticConnectionPool that allows itself to be reseeded at run time. * It comes with a very minor overhead of a ReaderWriterLock to ensure thread safety. */ [U] public void Sniffing() { var uris = Enumerable.Range(9200, 5).Select(p => new Uri("http://localhost:" + p)); /** a connection pool can be seeded using an enumerable of `Uri` */ var pool = new SniffingConnectionPool(uris); /** Or using an enumerable of `Node` * A major benefit here is you can include known node roles when seeding * NEST can use this information to favour sniffing on master eligable nodes first * and take master only nodes out of rotation for issueing client calls on. */ var nodes = uris.Select(u=>new Node(u)); pool = new SniffingConnectionPool(nodes); /** This type of pool is hardwirted to optout out sniffing*/ pool.SupportsReseeding.Should().BeTrue(); /** but supports pinging when enabled */ pool.SupportsPinging.Should().BeTrue(); /** To create a client using this siffing connection pool pass * the connection pool to the connectionsettings you pass to ElasticClient */ var client = new ElasticClient(new ConnectionSettings(pool)); client.ConnectionSettings.ConnectionPool.Should().BeOfType<SniffingConnectionPool>(); }
/** * This however is still a non-failover connection. Meaning if that `node` goes down the operation will not be retried on any other nodes in the cluster. * * To get a failover connection we have to pass an `IConnectionPool` instance instead of a `Uri`. */ public void InstantiatingAConnectionPoolClient() { var node = new Uri("http://mynode.example.com:8082/apiKey"); var connectionPool = new SniffingConnectionPool(new[] { node }); var config = new ConnectionConfiguration(connectionPool); var client = new ElasticsearchClient(config); }
private void ApplySettings(dynamic config) { _clients.Clear(); _config = (ESConfig)(config?.elasticsearch?.ToObject <ESConfig>()) ?? new ESConfig(); _connectionPools = _config.ConnectionPools?.ToDictionary(kvp => kvp.Key, kvp => { var c = kvp.Value; IConnectionPool pool; var endpoints = c.Endpoints.DefaultIfEmpty("http://localhost:9200").Select(endpoint => new Uri(endpoint)); if (c.Sniffing) { // var connectionEndpoints = ((JArray)config.esEndpoints).ToObject<string[]>(); pool = new Elasticsearch.Net.SniffingConnectionPool(endpoints); } else { pool = new Elasticsearch.Net.StaticConnectionPool(endpoints); } return(new ConnectionPool(pool, c.Credentials)); }) ?? new Dictionary <string, ConnectionPool>(); if (!_connectionPools.ContainsKey("default")) { _connectionPools.Add("default", new ConnectionPool(new Elasticsearch.Net.StaticConnectionPool(new[] { new Uri("http://localhost:9200") }), null)); } }
[U] public void SniffingPoolWithstandsConcurrentReadAndWrites() { var uris = Enumerable.Range(9200, NumberOfNodes).Select(p => new Uri("http://localhost:" + p)); var sniffingPool = new SniffingConnectionPool(uris, randomize: false); Action callSniffing = () => this.AssertCreateView(sniffingPool); callSniffing.ShouldNotThrow(); }
[U] public void EachViewStartsAtNexPositionAndWrapsOver() { var uris = Enumerable.Range(9200, NumberOfNodes).Select(p => new Uri("http://localhost:" + p)); var staticPool = new StaticConnectionPool(uris, randomize: false); var sniffingPool = new SniffingConnectionPool(uris, randomize: false); this.AssertCreateView(staticPool); this.AssertCreateView(sniffingPool); }
/** * Here instead of directly passing `node`, we pass a <<sniffing-connection-pool, SniffingConnectionPool>> * which will use our `node` to find out the rest of the available cluster nodes. * Be sure to read more about <<connection-pooling, Connection Pooling and Cluster Failover>>. * * === Configuration Options * *Besides either passing a `Uri` or `IConnectionPool` to `ConnectionConfiguration`, you can also fluently control many more options. For instance: */ public void SpecifyingClientOptions() { var node = new Uri("http://mynode.example.com:8082/apiKey"); var connectionPool = new SniffingConnectionPool(new[] { node }); var config = new ConnectionConfiguration(connectionPool) .DisableDirectStreaming() //<1> Additional options are fluent method calls on `ConnectionConfiguration` .BasicAuthentication("user", "pass") .RequestTimeout(TimeSpan.FromSeconds(5)); }
/** * Here instead of directly passing `node`, we pass a `SniffingConnectionPool` which will use our `node` to find out the rest of the available cluster nodes. * Be sure to read more about [Connection Pooling and Cluster Failover here](/elasticsearch-net/cluster-failover.html) * * ## Options * * Besides either passing a `Uri` or `IConnectionPool` to `ConnectionConfiguration`, you can also fluently control many more options. For instance: */ public void SpecifyingClientOptions() { //hide var node = new Uri("http://mynode.example.com:8082/apiKey"); var connectionPool = new SniffingConnectionPool(new[] { node }); //endhide var config = new ConnectionConfiguration(connectionPool) .DisableDirectStreaming() .BasicAuthentication("user", "pass") .RequestTimeout(TimeSpan.FromSeconds(5)); }
protected ConnectionSettings CreateSettings() { var host = Process.GetProcessesByName("fiddler").Any() ? "ipv4.fiddler" : "localhost"; var uri = new UriBuilder("http", host, Port).Uri; var connectionPool = new SniffingConnectionPool(new [] { uri }); return new ConnectionSettings(connectionPool) .SetDefaultIndex(IndexName) .SniffOnStartup() .ThrowExceptions(); }
public ElasticClient CreateEsClient() { var nodeUri = new Uri(_elasticSearchUrl); var connectionPool = new SniffingConnectionPool(new[] { nodeUri }); var connectionSettings = new ConnectionSettings(connectionPool) .MapDefaultTypeIndices(m => m.Add(typeof(KundeIndexItem), "kunder") ); var esClient = new ElasticClient(connectionSettings); return esClient; }