Module message

Module message 

Source
Expand description

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:

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:

use allora_core::message::{Message, Payload};
let msg = Message::from_text("hello");
assert_eq!(msg.body_text(), Some("hello"));

Adding and overriding headers:

use allora_core::message::Message;
let msg = Message::from_text("demo");
assert!(msg.header("missing").is_none());

Structs§

Exchange
An exchange wraps an inbound and outbound message, plus routing properties.
Message
A message containing a payload and headers (metadata).

Enums§

Payload
Represents the payload of a message, supporting text, bytes, JSON, or empty.
RawPayload
Represents the payload of a message, supporting text, bytes, JSON, or empty.