From 9151d61eda2a7b4fcce581faef5e22393dd49720 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Fri, 8 Jun 2018 16:33:57 -0700 Subject: [PATCH] allow to use custom resolver for ClientConnector --- CHANGES.md | 4 +++- src/client/connector.rs | 17 ++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 2fee070c4..9171a2372 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -28,7 +28,7 @@ * Remove `Route::with2()` and `Route::with3()` use tuple of extractors instead. -## [0.6.12] - 2018-06-07 +## [0.6.12] - 2018-06-08 ### Added @@ -38,6 +38,8 @@ * Improved failure interoperability with downcasting #285 +* Allow to use custom resolver for `ClientConnector` + ## [0.6.11] - 2018-06-05 diff --git a/src/client/connector.rs b/src/client/connector.rs index 431d4df32..61dda22ed 100644 --- a/src/client/connector.rs +++ b/src/client/connector.rs @@ -5,8 +5,9 @@ use std::{fmt, io, mem, time}; use actix::resolver::{Connect as ResolveConnect, Connector, ConnectorError}; use actix::{ - fut, Actor, ActorFuture, ActorResponse, AsyncContext, Context, ContextFutureSpawner, - Handler, Message, Recipient, StreamHandler, Supervised, SystemService, WrapFuture, + fut, Actor, ActorFuture, ActorResponse, Addr, AsyncContext, Context, + ContextFutureSpawner, Handler, Message, Recipient, StreamHandler, Supervised, + SystemService, WrapFuture, }; use futures::sync::{mpsc, oneshot}; @@ -197,6 +198,7 @@ pub struct ClientConnector { acq_tx: mpsc::UnboundedSender, acq_rx: Option>, + resolver: Addr, conn_lifetime: Duration, conn_keep_alive: Duration, limit: usize, @@ -240,6 +242,7 @@ impl Default for ClientConnector { subscriber: None, acq_tx: tx, acq_rx: Some(rx), + resolver: Connector::from_registry(), connector: builder.build().unwrap(), conn_lifetime: Duration::from_secs(75), conn_keep_alive: Duration::from_secs(15), @@ -263,6 +266,7 @@ impl Default for ClientConnector { subscriber: None, acq_tx: tx, acq_rx: Some(rx), + resolver: Connector::from_registry(), conn_lifetime: Duration::from_secs(75), conn_keep_alive: Duration::from_secs(15), limit: 100, @@ -329,6 +333,7 @@ impl ClientConnector { subscriber: None, acq_tx: tx, acq_rx: Some(rx), + resolver: Connector::from_registry(), conn_lifetime: Duration::from_secs(75), conn_keep_alive: Duration::from_secs(15), limit: 100, @@ -388,6 +393,12 @@ impl ClientConnector { self } + /// Use custom resolver actor + pub fn resolver(mut self, addr: Addr) -> Self { + self.resolver = addr; + self + } + fn acquire(&mut self, key: &Key) -> Acquire { // check limits if self.limit > 0 { @@ -655,7 +666,7 @@ impl Handler for ClientConnector { { ActorResponse::async( - Connector::from_registry() + self.resolver .send( ResolveConnect::host_and_port(&conn.0.host, port) .timeout(conn_timeout),