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