pub struct ServiceRegistry { /* private fields */ }Expand description
Production-ready service registry for the ZLayer reverse proxy.
Routes are stored as a Vec<RouteEntry> behind a tokio::sync::RwLock,
kept in longest-prefix-first order so that resolve() always returns
the most specific match.
Implementations§
Source§impl ServiceRegistry
impl ServiceRegistry
Sourcepub async fn register(&self, entry: RouteEntry)
pub async fn register(&self, entry: RouteEntry)
Register a route, maintaining longest-prefix-first order.
Sourcepub async fn unregister_service(&self, service_name: &str)
pub async fn unregister_service(&self, service_name: &str)
Remove all routes belonging to service_name.
Sourcepub async fn resolve(
&self,
host: Option<&str>,
path: &str,
) -> Option<ResolvedService>
pub async fn resolve( &self, host: Option<&str>, path: &str, ) -> Option<ResolvedService>
Resolve an incoming request to the best-matching ResolvedService.
Returns None when no route matches.
Sourcepub async fn update_backends(
&self,
service_name: &str,
backends: Vec<SocketAddr>,
)
pub async fn update_backends( &self, service_name: &str, backends: Vec<SocketAddr>, )
Replace the backend list for every route belonging to service_name.
Sourcepub async fn add_backend(&self, service_name: &str, addr: SocketAddr)
pub async fn add_backend(&self, service_name: &str, addr: SocketAddr)
Append a single backend address to every route belonging to service_name.
Sourcepub async fn remove_backend(&self, service_name: &str, addr: SocketAddr)
pub async fn remove_backend(&self, service_name: &str, addr: SocketAddr)
Remove a single backend address from every route belonging to service_name.
Sourcepub async fn list_services(&self) -> Vec<String>
pub async fn list_services(&self) -> Vec<String>
Return the unique set of service names across all registered routes.
Sourcepub async fn route_count(&self) -> usize
pub async fn route_count(&self) -> usize
Return the total number of registered routes.
Sourcepub async fn list_routes(&self) -> Vec<RouteEntry>
pub async fn list_routes(&self) -> Vec<RouteEntry>
Return a snapshot of all registered routes.