Skip to main content

camel_dsl/
model.rs

1pub use camel_api::{LanguageExpressionDef, ValueSourceDef};
2
3#[derive(Debug, Clone, PartialEq, Eq)]
4pub enum DeclarativeConcurrency {
5    Sequential,
6    Concurrent { max: Option<usize> },
7}
8
9#[derive(Debug, Clone, PartialEq, Eq)]
10pub struct DeclarativeCircuitBreaker {
11    pub failure_threshold: u32,
12    pub open_duration_ms: u64,
13}
14
15#[derive(Debug, Clone, PartialEq)]
16pub struct DeclarativeRetryPolicy {
17    pub max_attempts: u32,
18    pub initial_delay_ms: u64,
19    pub multiplier: f64,
20    pub max_delay_ms: u64,
21    pub handled_by: Option<String>,
22}
23
24#[derive(Debug, Clone, PartialEq)]
25pub struct DeclarativeErrorHandler {
26    pub dead_letter_channel: Option<String>,
27    pub retry: Option<DeclarativeRetryPolicy>,
28}
29
30#[derive(Debug, Clone)]
31pub struct DeclarativeRoute {
32    pub from: String,
33    pub route_id: String,
34    pub auto_startup: bool,
35    pub startup_order: i32,
36    pub concurrency: Option<DeclarativeConcurrency>,
37    pub error_handler: Option<DeclarativeErrorHandler>,
38    pub circuit_breaker: Option<DeclarativeCircuitBreaker>,
39    pub steps: Vec<DeclarativeStep>,
40}
41
42#[derive(Debug, Clone, PartialEq, Eq)]
43pub struct ToStepDef {
44    pub uri: String,
45}
46
47impl ToStepDef {
48    pub fn new(uri: impl Into<String>) -> Self {
49        Self { uri: uri.into() }
50    }
51}
52
53#[derive(Debug, Clone, PartialEq, Eq)]
54pub enum LogLevelDef {
55    Trace,
56    Debug,
57    Info,
58    Warn,
59    Error,
60}
61
62// Note: `Eq` is not derived because `ValueSourceDef` contains `serde_json::Value`
63// which does not implement `Eq` (due to floating-point fields).
64#[derive(Debug, Clone, PartialEq)]
65pub struct LogStepDef {
66    pub message: ValueSourceDef,
67    pub level: LogLevelDef,
68}
69
70impl LogStepDef {
71    pub fn info(message: impl Into<String>) -> Self {
72        Self {
73            message: ValueSourceDef::Literal(serde_json::Value::String(message.into())),
74            level: LogLevelDef::Info,
75        }
76    }
77}
78
79#[derive(Debug, Clone, PartialEq)]
80pub struct SetHeaderStepDef {
81    pub key: String,
82    pub value: ValueSourceDef,
83}
84
85impl SetHeaderStepDef {
86    pub fn literal(key: impl Into<String>, value: impl Into<String>) -> Self {
87        Self {
88            key: key.into(),
89            value: ValueSourceDef::Literal(serde_json::Value::String(value.into())),
90        }
91    }
92}
93
94#[derive(Debug, Clone, PartialEq)]
95pub struct SetBodyStepDef {
96    pub value: ValueSourceDef,
97}
98
99#[derive(Debug, Clone, PartialEq)]
100pub struct FilterStepDef {
101    pub predicate: LanguageExpressionDef,
102    pub steps: Vec<DeclarativeStep>,
103}
104
105#[derive(Debug, Clone, PartialEq)]
106pub struct WhenStepDef {
107    pub predicate: LanguageExpressionDef,
108    pub steps: Vec<DeclarativeStep>,
109}
110
111#[derive(Debug, Clone, PartialEq)]
112pub struct ChoiceStepDef {
113    pub whens: Vec<WhenStepDef>,
114    pub otherwise: Option<Vec<DeclarativeStep>>,
115}
116
117#[derive(Debug, Clone, PartialEq)]
118pub enum SplitExpressionDef {
119    BodyLines,
120    BodyJsonArray,
121    Language(LanguageExpressionDef),
122}
123
124#[derive(Debug, Clone, PartialEq, Eq)]
125pub enum SplitAggregationDef {
126    LastWins,
127    CollectAll,
128    Original,
129}
130
131#[derive(Debug, Clone, PartialEq)]
132pub struct SplitStepDef {
133    pub expression: SplitExpressionDef,
134    pub aggregation: SplitAggregationDef,
135    pub parallel: bool,
136    pub parallel_limit: Option<usize>,
137    pub stop_on_exception: bool,
138    pub steps: Vec<DeclarativeStep>,
139}
140
141#[derive(Debug, Clone, PartialEq, Eq)]
142pub enum AggregateStrategyDef {
143    CollectAll,
144}
145
146#[derive(Debug, Clone, PartialEq)]
147pub struct AggregateStepDef {
148    pub header: String,
149    pub completion_size: Option<usize>,
150    pub completion_timeout_ms: Option<u64>,
151    pub completion_predicate: Option<LanguageExpressionDef>,
152    pub strategy: AggregateStrategyDef,
153    pub max_buckets: Option<usize>,
154    pub bucket_ttl_ms: Option<u64>,
155}
156
157#[derive(Debug, Clone, PartialEq, Eq)]
158pub struct WireTapStepDef {
159    pub uri: String,
160}
161
162#[derive(Debug, Clone, PartialEq, Eq)]
163pub struct BeanStepDef {
164    pub name: String,
165    pub method: String,
166}
167
168impl BeanStepDef {
169    pub fn new(name: impl Into<String>, method: impl Into<String>) -> Self {
170        Self {
171            name: name.into(),
172            method: method.into(),
173        }
174    }
175}
176
177#[derive(Debug, Clone, PartialEq, Eq)]
178pub enum MulticastAggregationDef {
179    LastWins,
180    CollectAll,
181    Original,
182}
183
184#[derive(Debug, Clone, PartialEq)]
185pub struct MulticastStepDef {
186    pub steps: Vec<DeclarativeStep>,
187    pub parallel: bool,
188    pub parallel_limit: Option<usize>,
189    pub stop_on_exception: bool,
190    pub timeout_ms: Option<u64>,
191    pub aggregation: MulticastAggregationDef,
192}
193
194#[derive(Debug, Clone, PartialEq, Eq)]
195pub struct ScriptStepDef {
196    pub expression: LanguageExpressionDef,
197}
198
199#[derive(Debug, Clone, PartialEq, Eq)]
200pub enum BodyTypeDef {
201    Text,
202    Json,
203    Bytes,
204    Empty,
205}
206
207#[derive(Debug, Clone, PartialEq)]
208pub enum DeclarativeStep {
209    To(ToStepDef),
210    Log(LogStepDef),
211    SetHeader(SetHeaderStepDef),
212    SetBody(SetBodyStepDef),
213    Filter(FilterStepDef),
214    Choice(ChoiceStepDef),
215    Split(SplitStepDef),
216    Aggregate(AggregateStepDef),
217    WireTap(WireTapStepDef),
218    Multicast(MulticastStepDef),
219    Stop,
220    Script(ScriptStepDef),
221    ConvertBodyTo(BodyTypeDef),
222    Bean(BeanStepDef),
223}