Skip to main content

camel_api/
load_balancer.rs

1#[derive(Debug, Clone, Default, PartialEq, Eq)]
2pub enum LoadBalanceStrategy {
3    #[default]
4    RoundRobin,
5    Random,
6    Weighted(Vec<(String, u32)>),
7    Failover,
8}
9
10#[derive(Debug, Clone)]
11pub struct LoadBalancerConfig {
12    pub strategy: LoadBalanceStrategy,
13    pub parallel: bool,
14}
15
16impl LoadBalancerConfig {
17    pub fn round_robin() -> Self {
18        Self {
19            strategy: LoadBalanceStrategy::RoundRobin,
20            parallel: false,
21        }
22    }
23
24    pub fn random() -> Self {
25        Self {
26            strategy: LoadBalanceStrategy::Random,
27            parallel: false,
28        }
29    }
30
31    pub fn weighted(weights: Vec<(String, u32)>) -> Self {
32        Self {
33            strategy: LoadBalanceStrategy::Weighted(weights),
34            parallel: false,
35        }
36    }
37
38    pub fn failover() -> Self {
39        Self {
40            strategy: LoadBalanceStrategy::Failover,
41            parallel: false,
42        }
43    }
44
45    pub fn parallel(mut self, p: bool) -> Self {
46        self.parallel = p;
47        self
48    }
49}