camel-dsl 0.6.1

DSL support for rust-camel (YAML, etc)
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
use serde::Deserialize;

#[derive(Deserialize)]
pub struct YamlRoutes {
    pub routes: Vec<YamlRoute>,
}

#[derive(Deserialize)]
pub struct YamlRoute {
    pub id: String,
    pub from: String,
    #[serde(default)]
    pub steps: Vec<YamlStep>,
    #[serde(default = "default_true")]
    pub auto_startup: bool,
    #[serde(default = "default_startup_order")]
    pub startup_order: i32,
    #[serde(default)]
    pub sequential: bool,
    #[serde(default)]
    pub concurrent: Option<usize>,
    #[serde(default)]
    pub error_handler: Option<YamlErrorHandler>,
    #[serde(default)]
    pub circuit_breaker: Option<YamlCircuitBreaker>,
    #[serde(default)]
    pub on_complete: Option<String>,
    #[serde(default)]
    pub on_failure: Option<String>,
}

#[derive(Deserialize)]
pub struct YamlErrorHandler {
    #[serde(default)]
    pub dead_letter_channel: Option<String>,
    #[serde(default)]
    pub retry: Option<YamlRedeliveryPolicy>,
    #[serde(default)]
    pub on_exceptions: Option<Vec<YamlOnException>>,
}

#[derive(Deserialize)]
pub struct YamlOnException {
    #[serde(default)]
    pub kind: Option<String>,
    #[serde(default)]
    pub message_contains: Option<String>,
    #[serde(default)]
    pub retry: Option<YamlRedeliveryPolicy>,
}

#[derive(Deserialize)]
pub struct YamlRedeliveryPolicy {
    pub max_attempts: u32,
    #[serde(default = "default_initial_delay_ms")]
    pub initial_delay_ms: u64,
    #[serde(default = "default_multiplier")]
    pub multiplier: f64,
    #[serde(default = "default_max_delay_ms")]
    pub max_delay_ms: u64,
    #[serde(default = "default_jitter_factor")]
    pub jitter_factor: f64,
    #[serde(default)]
    pub handled_by: Option<String>,
}

#[derive(Deserialize)]
pub struct YamlCircuitBreaker {
    #[serde(default = "default_failure_threshold")]
    pub failure_threshold: u32,
    #[serde(default = "default_open_duration_ms")]
    pub open_duration_ms: u64,
}

fn default_true() -> bool {
    true
}

fn default_startup_order() -> i32 {
    1000
}

fn default_initial_delay_ms() -> u64 {
    100
}

fn default_multiplier() -> f64 {
    2.0
}

fn default_max_delay_ms() -> u64 {
    10_000
}

fn default_jitter_factor() -> f64 {
    0.0
}

fn default_failure_threshold() -> u32 {
    5
}

fn default_open_duration_ms() -> u64 {
    30_000
}

#[derive(Deserialize, Debug)]
pub struct DelayStep {
    pub delay: DelayBody,
}

#[derive(Deserialize, Debug)]
#[serde(untagged)]
pub enum DelayBody {
    Short(u64),
    Full(DelayFullConfig),
}

#[derive(Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct DelayFullConfig {
    pub delay_ms: u64,
    #[serde(default)]
    pub dynamic_header: Option<String>,
}

#[derive(Deserialize, Debug)]
#[serde(untagged)]
pub enum YamlStep {
    To(ToStep),
    SetHeader(SetHeaderStep),
    SetBody(SetBodyStep),
    Bean(BeanStep),
    Choice(ChoiceStep),
    DynamicRouter(DynamicRouterStep),
    Filter(FilterStep),
    LoadBalance(LoadBalanceStep),
    Log(LogStep),
    Split(SplitStep),
    Aggregate(AggregateStep),
    WireTap(WireTapStep),
    Multicast(MulticastStep),
    RoutingSlip(RoutingSlipStep),
    RecipientList(RecipientListStep),
    Stop(StopStep),
    Throttle(ThrottleStep),
    Transform(TransformStep),
    Script(ScriptStep),
    ConvertBodyTo(ConvertBodyToStep),
    Marshal(MarshalStep),
    Unmarshal(UnmarshalStep),
    Delay(DelayStep),
}

#[derive(Deserialize, Debug)]
pub struct ToStep {
    pub to: String,
}

#[derive(Deserialize, Debug)]
pub struct SetHeaderStep {
    pub set_header: SetHeaderData,
}

#[derive(Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct SetHeaderData {
    pub key: String,
    #[serde(default)]
    pub value: Option<serde_json::Value>,
    #[serde(default)]
    pub language: Option<String>,
    #[serde(default)]
    pub source: Option<String>,
    #[serde(default)]
    pub simple: Option<String>,
    #[serde(default)]
    pub rhai: Option<String>,
    #[serde(default)]
    pub jsonpath: Option<String>,
    #[serde(default)]
    pub xpath: Option<String>,
}

#[derive(Deserialize, Debug)]
pub struct SetBodyStep {
    pub set_body: SetBodyData,
}

/// `transform:` step — alias for `set_body:`, reuses all SetBodyData types.
#[derive(Deserialize, Debug)]
pub struct TransformStep {
    pub transform: SetBodyData,
}

#[derive(Deserialize, Debug)]
#[serde(untagged)]
pub enum SetBodyData {
    // Config must be tried BEFORE Literal: serde_json::Value matches any YAML value (including
    // objects), so it would greedily swallow `{ simple: "..." }` as a Literal JSON object
    // instead of a SetBodyConfig. By placing Config first, structured forms like
    // `set_body: { simple: "..." }` deserialize correctly.
    Config(SetBodyConfig),
    Literal(serde_json::Value),
}

#[derive(Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct SetBodyConfig {
    #[serde(default)]
    pub value: Option<serde_json::Value>,
    #[serde(default)]
    pub language: Option<String>,
    #[serde(default)]
    pub source: Option<String>,
    #[serde(default)]
    pub simple: Option<String>,
    #[serde(default)]
    pub rhai: Option<String>,
    #[serde(default)]
    pub jsonpath: Option<String>,
    #[serde(default)]
    pub xpath: Option<String>,
}

#[derive(Deserialize, Debug)]
#[serde(untagged)]
pub enum LogBody {
    Message(String),
    Config(LogConfig),
}

#[derive(Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct LogConfig {
    /// The log message. Can be a plain string literal or a nested expression object.
    pub message: LogMessageData,
    #[serde(default)]
    pub level: Option<String>,
}

/// The `message` field inside a `log: { message: ... }` config block.
/// Either a bare string literal or a value-source expression (simple, rhai, language+source).
#[derive(Deserialize, Debug)]
#[serde(untagged)]
pub enum LogMessageData {
    Literal(String),
    Expr(LogMessageExpr),
}

#[derive(Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct LogMessageExpr {
    #[serde(default)]
    pub value: Option<String>,
    #[serde(default)]
    pub language: Option<String>,
    #[serde(default)]
    pub source: Option<String>,
    #[serde(default)]
    pub simple: Option<String>,
    #[serde(default)]
    pub rhai: Option<String>,
    #[serde(default)]
    pub jsonpath: Option<String>,
    #[serde(default)]
    pub xpath: Option<String>,
}

#[derive(Deserialize, Debug)]
pub struct LogStep {
    pub log: LogBody,
}

#[derive(Deserialize, Debug)]
pub struct FilterStep {
    pub filter: PredicateBlock,
}

#[derive(Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct PredicateBlock {
    #[serde(default)]
    pub language: Option<String>,
    #[serde(default)]
    pub source: Option<String>,
    #[serde(default)]
    pub simple: Option<String>,
    #[serde(default)]
    pub rhai: Option<String>,
    #[serde(default)]
    pub jsonpath: Option<String>,
    #[serde(default)]
    pub xpath: Option<String>,
    #[serde(default)]
    pub steps: Vec<YamlStep>,
}

#[derive(Deserialize, Debug)]
pub struct ChoiceStep {
    pub choice: ChoiceData,
}

#[derive(Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct ChoiceData {
    #[serde(default)]
    pub when: Vec<PredicateBlock>,
    #[serde(default)]
    pub otherwise: Option<Vec<YamlStep>>,
}

#[derive(Deserialize, Debug)]
pub struct SplitStep {
    pub split: SplitData,
}

#[derive(Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct SplitData {
    #[serde(default)]
    pub expression: Option<SplitExpressionYaml>,
    #[serde(default = "default_split_aggregation")]
    pub aggregation: String,
    #[serde(default)]
    pub parallel: bool,
    #[serde(default)]
    pub parallel_limit: Option<usize>,
    #[serde(default = "default_true")]
    pub stop_on_exception: bool,
    #[serde(default)]
    pub steps: Vec<YamlStep>,
}

#[derive(Deserialize, Debug, Clone)]
#[serde(untagged)]
pub enum SplitExpressionYaml {
    Simple(String),
    Config(SplitExpressionConfig),
}

#[derive(Deserialize, Debug, Clone)]
#[serde(deny_unknown_fields)]
pub struct SplitExpressionConfig {
    #[serde(default)]
    pub language: Option<String>,
    #[serde(default)]
    pub source: Option<String>,
    #[serde(default)]
    pub simple: Option<String>,
    #[serde(default)]
    pub rhai: Option<String>,
    #[serde(default)]
    pub jsonpath: Option<String>,
    #[serde(default)]
    pub xpath: Option<String>,
}

fn default_split_aggregation() -> String {
    "last_wins".to_string()
}

#[derive(Deserialize, Debug)]
pub struct AggregateStep {
    pub aggregate: AggregateData,
}

#[derive(Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct AggregateData {
    pub header: String,
    #[serde(default)]
    pub correlation_key: Option<String>,
    #[serde(default)]
    pub completion_size: Option<usize>,
    #[serde(default)]
    pub completion_timeout_ms: Option<u64>,
    #[serde(default)]
    pub completion_predicate: Option<PredicateBlock>,
    #[serde(default = "default_aggregate_strategy")]
    pub strategy: String,
    #[serde(default)]
    pub max_buckets: Option<usize>,
    #[serde(default)]
    pub bucket_ttl_ms: Option<u64>,
    #[serde(default)]
    pub force_completion_on_stop: Option<bool>,
    #[serde(default)]
    pub discard_on_timeout: Option<bool>,
}

fn default_aggregate_strategy() -> String {
    "collect_all".to_string()
}

#[derive(Deserialize, Debug)]
pub struct WireTapStep {
    pub wire_tap: String,
}

#[derive(Deserialize, Debug)]
pub struct MulticastStep {
    pub multicast: MulticastData,
}

#[derive(Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct MulticastData {
    #[serde(default)]
    pub parallel: bool,
    #[serde(default)]
    pub parallel_limit: Option<usize>,
    #[serde(default)]
    pub stop_on_exception: bool,
    #[serde(default)]
    pub timeout_ms: Option<u64>,
    #[serde(default = "default_multicast_aggregation")]
    pub aggregation: String,
    #[serde(default)]
    pub steps: Vec<YamlStep>,
}

fn default_multicast_aggregation() -> String {
    "last_wins".to_string()
}

#[derive(Deserialize, Debug)]
pub struct StopStep {
    pub stop: bool,
}

#[derive(Deserialize, Debug)]
pub struct ScriptStep {
    pub script: ScriptData,
}

#[derive(Deserialize, Debug)]
pub struct ConvertBodyToStep {
    pub convert_body_to: String,
}

#[derive(Deserialize, Debug)]
pub struct MarshalStep {
    pub marshal: String,
}

#[derive(Deserialize, Debug)]
pub struct UnmarshalStep {
    pub unmarshal: String,
}

#[derive(Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct ScriptData {
    pub language: String,
    pub source: String,
}

#[derive(Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct ThrottleStep {
    pub throttle: ThrottleData,
}

#[derive(Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct ThrottleData {
    pub max_requests: usize,
    #[serde(default = "default_throttle_period_secs")]
    pub period_secs: u64,
    #[serde(default)]
    pub strategy: Option<String>,
    #[serde(default)]
    pub steps: Vec<YamlStep>,
}

fn default_throttle_period_secs() -> u64 {
    1
}

#[derive(Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct LoadBalanceStep {
    pub load_balance: LoadBalanceData,
}

#[derive(Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct LoadBalanceData {
    #[serde(default = "default_lb_strategy")]
    pub strategy: String,
    #[serde(default)]
    pub distribution_ratio: Option<String>,
    #[serde(default)]
    pub parallel: bool,
    #[serde(default)]
    pub steps: Vec<YamlStep>,
}

fn default_lb_strategy() -> String {
    "round_robin".to_string()
}

#[derive(Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct DynamicRouterStep {
    pub dynamic_router: DynamicRouterData,
}

#[derive(Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct DynamicRouterData {
    #[serde(default)]
    pub simple: Option<String>,
    #[serde(default)]
    pub rhai: Option<String>,
    #[serde(default)]
    pub language: Option<String>,
    #[serde(default)]
    pub source: Option<String>,
    #[serde(default = "default_uri_delimiter")]
    pub uri_delimiter: String,
    #[serde(default = "default_cache_size")]
    pub cache_size: i32,
    #[serde(default)]
    pub ignore_invalid_endpoints: bool,
    #[serde(default = "default_max_iterations")]
    pub max_iterations: usize,
}

fn default_uri_delimiter() -> String {
    ",".to_string()
}

fn default_cache_size() -> i32 {
    1000
}

fn default_max_iterations() -> usize {
    1000
}

#[derive(Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct RoutingSlipStep {
    pub routing_slip: RoutingSlipData,
}

#[derive(Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct RoutingSlipData {
    #[serde(default)]
    pub simple: Option<String>,
    #[serde(default)]
    pub rhai: Option<String>,
    #[serde(default)]
    pub language: Option<String>,
    #[serde(default)]
    pub source: Option<String>,
    #[serde(default = "default_uri_delimiter")]
    pub uri_delimiter: String,
    #[serde(default = "default_cache_size")]
    pub cache_size: i32,
    #[serde(default)]
    pub ignore_invalid_endpoints: bool,
}

#[derive(Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct RecipientListStep {
    pub recipient_list: RecipientListData,
}

#[derive(Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct RecipientListData {
    #[serde(default)]
    pub simple: Option<String>,
    #[serde(default)]
    pub rhai: Option<String>,
    #[serde(default)]
    pub language: Option<String>,
    #[serde(default)]
    pub source: Option<String>,
    #[serde(default = "default_uri_delimiter")]
    pub delimiter: String,
    #[serde(default)]
    pub parallel: bool,
    #[serde(default)]
    pub parallel_limit: Option<usize>,
    #[serde(default)]
    pub stop_on_exception: bool,
    #[serde(default)]
    pub strategy: Option<String>,
}

#[derive(Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct BeanStep {
    pub bean: BeanStepData,
}

#[derive(Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct BeanStepData {
    pub name: String,
    pub method: String,
}