Expand description
rustlavel-discovery: a service registry, and the client that uses it.
Read this before reaching for it. On Kubernetes, ECS or Nomad you do not
need a registry: the platform already knows which instances are ready and
already balances across them, and a registry there is a second copy of that
fact which will eventually disagree with the first. Use
Dns. This crate is for the case the platforms do not
cover — services on plain machines or across two clouds, or a Spring estate
already speaking Eureka that a Rustlavel service has to join.
Three answers to “where is this service” sit behind one trait, so moving between them is a line of configuration rather than a rewrite:
Static— the list you wrote. Where everybody starts, and where a great many applications correctly stay.Dns— a name the platform already resolves.Discovery— this registry, with a cache that outlives the registry being down.
§Running a registry
App::new()
.plugin(RegistryServer::new().peers(Peers::new(nodes).excluding(own_url)))
.run()
.awaitIt speaks Eureka’s wire format, so a Spring Cloud service registers against it with its stock configuration and nothing else changed.
§Joining one
let registrar = Arc::new(Registrar::new(nodes, Instance::new("orders", host, port)));
registrar.clone().start();§What this deliberately does not do
The registry is in memory and there is no timer evicting anything. Both are
on purpose. Persistence would buy nothing — every instance re-registers
within a heartbeat of a restart, so the state rebuilds itself faster than it
could be loaded, and a durable copy would only ever be wrong on the way
back up. And staleness is decided by whoever reads, not by a sweep: it is
what lets the registry notice that most of itself went quiet at once and
conclude that the network broke rather than that the estate died. See
registry.
Re-exports§
pub use client::Discovery;pub use client::Registrar;pub use instance::Instance;pub use instance::Status;pub use registry::Mode;pub use registry::Registry;pub use replicate::Change;pub use replicate::Peers;pub use resolve::Balance;pub use resolve::Dns;pub use resolve::Resolve;pub use resolve::RoundRobin;pub use resolve::Static;pub use server::RegistryServer;
Modules§
- client
- The other side of the registry: registering yourself, and finding everyone else.
- eureka
- Eureka’s wire format, so a Spring service can register here unmodified.
- instance
- One running copy of a service, and what the registry knows about it.
- registry
- What the registry holds, and how it decides who is alive.
- replicate
- Keeping several registries in agreement.
- resolve
- Turning a service name into an address.
- server
- The registry, as something you can run.
- ui
- What the registry looks like, for a person.