Struct ns_env_config::Router
[−]
[src]
pub struct Router { /* fields omitted */ }
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.
Methods
impl Router
[src]
fn from_config(config: &Arc<Config>, handle: &Handle) -> Router
[src]
Create a router for a static config
fn from_stream<S>(stream: S, handle: &Handle) -> Router where
S: Stream<Item = Arc<Config>, Error = Void> + 'static,
[src]
S: Stream<Item = Arc<Config>, Error = Void> + 'static,
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.
fn updating_config(
config: &Arc<Config>,
handle: &Handle
) -> (Router, UpdateSink)
[src]
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.
fn subscribe_many<'x, I>(&self, iter: I, default_port: u16) -> AddrStream where
I: IntoIterator,
<I as IntoIterator>::Item: Into<AutoName<'x>>,
[src]
I: IntoIterator,
<I as IntoIterator>::Item: Into<AutoName<'x>>,
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).
fn subscribe_many_stream<'x, S>(
&self,
stream: S,
default_port: u16
) -> AddrStream where
S: Stream + Send + 'static,
<S as Stream>::Item: IntoIterator,
<S as Stream>::Error: Display,
<<S as Stream>::Item as IntoIterator>::Item: Into<AutoName<'x>>,
[src]
&self,
stream: S,
default_port: u16
) -> AddrStream where
S: Stream + Send + 'static,
<S as Stream>::Item: IntoIterator,
<S as Stream>::Error: Display,
<<S as Stream>::Item as IntoIterator>::Item: Into<AutoName<'x>>,
: use subscribe_stream()
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.
fn subscribe_stream<S>(&self, stream: S, default_port: u16) -> AddrStream where
S: Stream + Send + 'static,
<S as Stream>::Error: Display,
<S as Stream>::Item: IntoNameIter<'x>,
[src]
S: Stream + Send + 'static,
<S as Stream>::Error: Display,
<S as Stream>::Item: IntoNameIter<'x>,
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.
fn resolve_auto<'x, N>(&self, name: N, default_port: u16) -> ResolveFuture where
N: Into<AutoName<'x>>,
[src]
N: Into<AutoName<'x>>,
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
[AutoName
]:
Trait Implementations
impl Clone for Router
[src]
impl Resolve for Router
[src]
type Future = ResolveFuture
fn resolve(&self, name: &Name) -> ResolveFuture
[src]
impl HostSubscribe for Router
[src]
type HostError = Void
type HostStream = HostStream
fn subscribe_host(&self, name: &Name) -> HostStream
[src]
impl Debug for Router
[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result<(), Error>
[src]
Formats the value using the given formatter.
impl Subscribe for Router
[src]
impl HostResolve for Router
[src]
type HostFuture = ResolveHostFuture
A future returned from resolve()
fn resolve_host(&self, name: &Name) -> ResolveHostFuture
[src]
Resolve a name to an address once
fn frozen_host_subscriber(self) -> FrozenSubscriber<Self>
[src]
Create a subscriber that resolves once using this resolver and never updates a stream Read more
fn null_service_resolver(self) -> NullResolver<Self>
[src]
Create a thing that implements Resolve+HostResolve but returns NameNotFound
on resolve
Read more