Skip to main content

camel_api/
recipient_list.rs

1use std::sync::Arc;
2
3use crate::Exchange;
4
5pub type RecipientListExpression = Arc<dyn Fn(&Exchange) -> String + Send + Sync>;
6
7#[derive(Clone)]
8pub struct RecipientListConfig {
9    pub expression: RecipientListExpression,
10    pub delimiter: String,
11    pub parallel: bool,
12    pub parallel_limit: Option<usize>,
13    pub stop_on_exception: bool,
14    pub strategy: crate::MulticastStrategy,
15}
16
17impl RecipientListConfig {
18    pub fn new(expression: RecipientListExpression) -> Self {
19        Self {
20            expression,
21            delimiter: ",".to_string(),
22            parallel: false,
23            parallel_limit: None,
24            stop_on_exception: false,
25            strategy: crate::MulticastStrategy::default(),
26        }
27    }
28
29    pub fn delimiter(mut self, d: impl Into<String>) -> Self {
30        self.delimiter = d.into();
31        self
32    }
33
34    pub fn parallel(mut self, parallel: bool) -> Self {
35        self.parallel = parallel;
36        self
37    }
38
39    pub fn parallel_limit(mut self, limit: usize) -> Self {
40        self.parallel_limit = Some(limit);
41        self
42    }
43
44    pub fn stop_on_exception(mut self, stop: bool) -> Self {
45        self.stop_on_exception = stop;
46        self
47    }
48
49    pub fn strategy(mut self, strategy: crate::MulticastStrategy) -> Self {
50        self.strategy = strategy;
51        self
52    }
53}
54
55impl std::fmt::Debug for RecipientListConfig {
56    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
57        f.debug_struct("RecipientListConfig")
58            .field("delimiter", &self.delimiter)
59            .field("parallel", &self.parallel)
60            .field("parallel_limit", &self.parallel_limit)
61            .field("stop_on_exception", &self.stop_on_exception)
62            .finish()
63    }
64}