pub struct Router { /* private fields */ }
Expand description
An actual router class
Note: when router is shut down (when config stream is closed), all futures and subscriptions are canceled.
Since 0.1.3: when all instances of Router are dropped the underlying
futures and streams continue to work, until all of them finish (for
subscriptions it means subscriber is dropped). In previous versions this
dropped all requests immediately. This was common source of confusion and
we consider this a bug. If you want to force close all futures and
subscriptions create a router with from_stream
or updating_config
and
send EOS on stream or drop UpdatingSink
respectively.
Implementations§
Source§impl Router
impl Router
Sourcepub fn from_config(config: &Arc<Config>, handle: &Handle) -> Router
pub fn from_config(config: &Arc<Config>, handle: &Handle) -> Router
Create a router for a static config
Sourcepub fn from_stream<S>(stream: S, handle: &Handle) -> Router
pub fn from_stream<S>(stream: S, handle: &Handle) -> Router
Create a router with updating config
Note: router is defunctional until first config is received in a stream. By defunctional we mean that every request will wait, until configured.
Note 2: when stream is closed router is shut down, so usually the stream must be infinite.
Sourcepub fn updating_config(
config: &Arc<Config>,
handle: &Handle,
) -> (Router, UpdateSink)
pub fn updating_config( config: &Arc<Config>, handle: &Handle, ) -> (Router, UpdateSink)
Create a router and update channel
Note: router is shut down when UpdateSink
is dropped. So keep
it somewhere so you can update config.
Sourcepub fn subscribe_many<'x, I>(&self, iter: I, default_port: u16) -> AddrStream
pub fn subscribe_many<'x, I>(&self, iter: I, default_port: u16) -> AddrStream
Subscribes to a list of names
This is intended to keep list of services in configuration file, like this (yaml):
addresses:
- example.org:8080
- _my._svc.example.org # SVC record
- example.net # default port
You can also specify a way to resolve the service by providing
iterator over AutoName
instances instead of plain &str
(both are
accepted in this method).
Sourcepub fn subscribe_many_stream<'x, S>(
&self,
stream: S,
default_port: u16,
) -> AddrStream
👎Deprecated since 0.1.1: use subscribe_stream()
pub fn subscribe_many_stream<'x, S>( &self, stream: S, default_port: u16, ) -> AddrStream
Subscribes to a stream that yields lists of names
See the description of subscribe_many
for the description of the list of names that must be yielded from
the stream.
Note: this is meant for configuration update scenario. I.e. when configuration is reloaded and new list of names is received, it should be pushed to this stream. The items received in the stream are non-cumulative and replace previous list.
Note 2: If stream is errored or end-of-stream reached, this means
name is not needed any more and its AddrStream
will be shut down,
presumably shutting down everything that depends on it.
Sourcepub fn subscribe_stream<S>(&self, stream: S, default_port: u16) -> AddrStream
pub fn subscribe_stream<S>(&self, stream: S, default_port: u16) -> AddrStream
Subscribes to a stream that yields lists of names
See the description of subscribe_many
for the description of the list of names that must be yielded from
the stream.
Note: this is meant for configuration update scenario. I.e. when configuration is reloaded and new list of names is received, it should be pushed to this stream. The items received in the stream are non-cumulative and replace previous list.
Note 2: If stream is errored or end-of-stream reached, this means
name is not needed any more and its AddrStream
will be shut down,
presumably shutting down everything that depends on it.
Sourcepub fn resolve_auto<'x, N: Into<AutoName<'x>>>(
&self,
name: N,
default_port: u16,
) -> ResolveFuture
pub fn resolve_auto<'x, N: Into<AutoName<'x>>>( &self, name: N, default_port: u16, ) -> ResolveFuture
Resolve a string or other things into an address
See description of subscribe_many
to find out how names are parsed
See AutoName
for supported types
Trait Implementations§
Source§impl HostResolve for Router
impl HostResolve for Router
Source§type HostFuture = ResolveHostFuture
type HostFuture = ResolveHostFuture
resolve()
Source§fn resolve_host(&self, name: &Name) -> ResolveHostFuture
fn resolve_host(&self, name: &Name) -> ResolveHostFuture
Source§fn frozen_host_subscriber(self) -> FrozenSubscriber<Self>where
Self: Sized,
fn frozen_host_subscriber(self) -> FrozenSubscriber<Self>where
Self: Sized,
Source§fn null_service_resolver(self) -> NullResolver<Self>where
Self: Sized,
fn null_service_resolver(self) -> NullResolver<Self>where
Self: Sized,
Source§impl HostSubscribe for Router
impl HostSubscribe for Router
Source§type HostStream = HostStream
type HostStream = HostStream
subscribe()
Source§fn subscribe_host(&self, name: &Name) -> HostStream
fn subscribe_host(&self, name: &Name) -> HostStream
Source§impl Resolve for Router
impl Resolve for Router
Source§type Future = ResolveFuture
type Future = ResolveFuture
resolve()
Source§fn resolve(&self, name: &Name) -> ResolveFuture
fn resolve(&self, name: &Name) -> ResolveFuture
Source§fn frozen_subscriber(self) -> FrozenSubscriber<Self>
fn frozen_subscriber(self) -> FrozenSubscriber<Self>
Source§fn frozen_service_subscriber(self) -> FrozenSubscriber<Self>where
Self: Sized,
fn frozen_service_subscriber(self) -> FrozenSubscriber<Self>where
Self: Sized,
Source§fn null_host_resolver(self) -> NullHostResolver<Self>where
Self: Sized,
fn null_host_resolver(self) -> NullHostResolver<Self>where
Self: Sized,
NameNotFound
on resolve_host
Read moreAuto Trait Implementations§
impl Freeze for Router
impl !RefUnwindSafe for Router
impl Send for Router
impl Sync for Router
impl Unpin for Router
impl !UnwindSafe for Router
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> SubscribeExt for Twhere
T: Resolve + HostResolve,
impl<T> SubscribeExt for Twhere
T: Resolve + HostResolve,
Source§fn interval_subscriber(
self,
interval: Duration,
handle: &Handle,
) -> IntervalSubscriber<T>
fn interval_subscriber( self, interval: Duration, handle: &Handle, ) -> IntervalSubscriber<T>
resolve
or resolve_host
at a regular
interval