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
//! Messaging core types: `Payload`, `Message`, and `Exchange`.
//!
//! # Overview
//! These types model the fundamental unit that flows through a Route / processors.
//! * `Payload` – concrete body representation (text, bytes, json, empty).
//! * `Message` – wraps a `Payload` plus string key/value headers (metadata).
//! * `Exchange` – carries an inbound `Message`, an optional outbound `Message`, and free-form properties used during routing.
//!
//! # IDs & Correlation
//! Every `Message` automatically gets a unique `message_id` header when constructed via `Message::new` / `Message::from_text`.
//! A `correlation_id` is NOT generated automatically—call `Message::ensure_correlation_id()` or `Exchange::correlation_id()` (or use the `CorrelationInitializer` processor / `Route::with_correlation`) to lazily create one when needed (aggregation, split/join, request/reply, etc.).
//!
//! # Headers vs Properties
//! * Headers live on the `Message` and are typically serialized/shared externally.
//! * Properties live on the `Exchange` and are intended for transient, internal routing state.
//! Choose headers when downstream systems or processors need the metadata; choose properties for ephemeral routing hints.
//!
//! # Thread Safety / Mutation
//! These types are plain structs; mutation requires &mut access. If sharing between threads, wrap in synchronization primitives (e.g. Arc<Mutex<_>>). The library leaves concurrency control to callers for flexibility.
//!
//! # Serialization
//! All types derive `Serialize`/`Deserialize` unconditionally; JSON bodies use `serde_json::Value`.
//!
//! # Examples
//! Basic creation:
//! ```no_run
//! use allora_core::message::{Exchange, Message};
//! let mut ex = Exchange::new(Message::from_text("ping"));
//! assert_eq!(ex.in_msg.body_text(), Some("ping"));
//! ```
//!
//! With bytes payload:
//! ```no_run
//! use allora_core::message::{Message, Payload};
//! let msg = Message::from_text("hello");
//! assert_eq!(msg.body_text(), Some("hello"));
//! ```
//!
//! Adding and overriding headers:
//! ```no_run
//! use allora_core::message::Message;
//! let msg = Message::from_text("demo");
//! assert!(msg.header("missing").is_none());
//! ```
//! [`CorrelationInitializer`]: crate::patterns::correlation_initializer::CorrelationInitializer
//! [`Route::with_correlation`]: crate::route::Route::with_correlation
use ;
use HashMap;
/// Represents the payload of a message, supporting text, bytes, JSON, or empty.
/// A message containing a payload and headers (metadata).
///
/// # Automatic Message ID
/// On construction a UUID v4 is inserted under the `message_id` header. While you *can*
/// override this with `set_header`, it is discouraged—other infrastructure (logging, tracing)
/// may rely on uniqueness.
///
/// # Correlation ID
/// Not created automatically to avoid overhead if unused. Call [`Message::ensure_correlation_id`]
/// when a processor needs it. Subsequent calls return the same stable value.
///
/// # Header Semantics
/// All headers are simple UTF-8 strings. Keep values small; store large / complex structures
/// in the payload or properties instead.
/// An exchange wraps an inbound and outbound message, plus routing properties.
///
/// # Inbound vs Outbound
/// * `in_msg` – original message entering the pipeline.
/// * `out_msg` – optional transformed result set by processors (e.g. formatter, enricher).
///
/// # Properties
/// Free-form key/value pairs for internal routing state (e.g. retry count, timing info).
/// Not automatically serialized; use headers for externally visible metadata.
///
/// # Correlation Helper
/// `Exchange::correlation_id` provides a convenience wrapper around `in_msg.ensure_correlation_id()`.
/// Alias for Payload type.
pub use Payload as RawPayload;