Skip to content

Commit 7556a70

Browse files
committed
Create constructors for static and sniffing node pool transports
1 parent fedd490 commit 7556a70

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

elasticsearch/src/http/transport.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ impl Transport {
349349
}
350350

351351
/// Creates a new instance of a [Transport] configured with a
352-
/// [StaticNodeListConnectionPool]
352+
/// [MultiNodeConnectionPool] that does not refresh
353353
pub fn static_node_list(urls: Vec<&str>) -> Result<Transport, Error> {
354354
let urls: Vec<Url> = urls
355355
.iter()
@@ -360,6 +360,23 @@ impl Transport {
360360
Ok(transport)
361361
}
362362

363+
/// Creates a new instance of a [Transport] configured with a
364+
/// [MultiNodeConnectionPool]
365+
///
366+
/// * `reseed_frequency` - frequency at which connections should be refreshed in seconds
367+
pub fn sniffing_node_list(
368+
urls: Vec<&str>,
369+
reseed_frequency: Duration,
370+
) -> Result<Transport, Error> {
371+
let urls: Vec<Url> = urls
372+
.iter()
373+
.map(|url| Url::parse(url))
374+
.collect::<Result<Vec<_>, _>>()?;
375+
let conn_pool = MultiNodeConnectionPool::round_robin(urls, Some(reseed_frequency));
376+
let transport = TransportBuilder::new(conn_pool).build()?;
377+
Ok(transport)
378+
}
379+
363380
/// Creates a new instance of a [Transport] configured for use with
364381
/// [Elasticsearch service in Elastic Cloud](https://www.elastic.co/cloud/).
365382
///

0 commit comments

Comments
 (0)