pub trait LoadBalancer: Send + Sync {
// Required methods
fn select<'life0, 'life1, 'async_trait>(
&'life0 self,
context: Option<&'life1 RequestContext>,
) -> Pin<Box<dyn Future<Output = ZentinelResult<TargetSelection>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn report_health<'life0, 'life1, 'async_trait>(
&'life0 self,
address: &'life1 str,
healthy: bool,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn healthy_targets<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Vec<String>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
// Provided methods
fn session_signing_key(&self) -> Option<[u8; 32]> { ... }
fn release<'life0, 'life1, 'async_trait>(
&'life0 self,
_selection: &'life1 TargetSelection,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn report_result<'life0, 'life1, 'async_trait>(
&'life0 self,
_selection: &'life1 TargetSelection,
_success: bool,
_latency: Option<Duration>,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn report_result_with_latency<'life0, 'life1, 'async_trait>(
&'life0 self,
address: &'life1 str,
success: bool,
_latency: Option<Duration>,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
}Expand description
Load balancer trait for different algorithms
Required Methods§
Sourcefn select<'life0, 'life1, 'async_trait>(
&'life0 self,
context: Option<&'life1 RequestContext>,
) -> Pin<Box<dyn Future<Output = ZentinelResult<TargetSelection>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn select<'life0, 'life1, 'async_trait>(
&'life0 self,
context: Option<&'life1 RequestContext>,
) -> Pin<Box<dyn Future<Output = ZentinelResult<TargetSelection>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Select next upstream target
Provided Methods§
Sourcefn session_signing_key(&self) -> Option<[u8; 32]>
fn session_signing_key(&self) -> Option<[u8; 32]>
The key this balancer signs session-affinity cookies with, if it signs any.
Used to assert that rebuilding a pool — which service discovery does whenever the target set changes — does not rotate the key and invalidate every cookie already issued.
Sourcefn release<'life0, 'life1, 'async_trait>(
&'life0 self,
_selection: &'life1 TargetSelection,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn release<'life0, 'life1, 'async_trait>(
&'life0 self,
_selection: &'life1 TargetSelection,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Release connection (for connection tracking)
Sourcefn report_result<'life0, 'life1, 'async_trait>(
&'life0 self,
_selection: &'life1 TargetSelection,
_success: bool,
_latency: Option<Duration>,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn report_result<'life0, 'life1, 'async_trait>(
&'life0 self,
_selection: &'life1 TargetSelection,
_success: bool,
_latency: Option<Duration>,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Report request result (for adaptive algorithms)
Sourcefn report_result_with_latency<'life0, 'life1, 'async_trait>(
&'life0 self,
address: &'life1 str,
success: bool,
_latency: Option<Duration>,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn report_result_with_latency<'life0, 'life1, 'async_trait>(
&'life0 self,
address: &'life1 str,
success: bool,
_latency: Option<Duration>,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Report request result by address with latency (for adaptive algorithms)
This method allows reporting results without needing the full TargetSelection, which is useful when the selection is not available (e.g., in logging callback). The default implementation just calls report_health; adaptive balancers override this to update their metrics.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".