Path: redb-route/redb.Route/Abstractions/IMessage.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route/Abstractions/IMessage.cs
----
using redb.Route.Core;
namespace redb.Route.Abstractions;
///
/// Represents a message flowing through the route pipeline.
/// Contains payload (Body), metadata (Headers), and supports both
/// C# idiomatic properties and Java-style methods for backward compatibility.
///
public interface IMessage
{
// ── C# idiomatic API ──
/// Message payload. Can be any object or null.
object? Body { get; set; }
///
/// MIME content type of the message body (e.g. "application/json").
/// Set by transport consumers from protocol-native metadata.
/// Null means unknown — no assumptions about body format.
///
string? ContentType { get; set; }
///
/// Headers that travel with the message (ContentType, CorrelationId, custom).
/// These headers are propagated to brokers when sending.
///
IDictionary Headers { get; }
/// Gets a header value with type conversion.
/// Target type for the header value.
/// Header key.
///
/// The converted value; default when the header is missing or has no conversion to
/// (as Camel's getHeader(name, type)).
///
/// The value cannot be parsed as .
T? GetHeader(string key);
///
/// Attachments of this message (Apache Camel's AttachmentMessage): named content beside the body, such as the
/// files of a form upload or of an e-mail. They belong to the message, not to the exchange, so In and
/// Out carry their own; a broker producer does not send them unless its protocol has a place for them.
/// implements them; a message type that does not answers with an empty list that
/// refuses additions.
///
IMessageAttachments Attachments => Core.MessageAttachments.Unsupported;
///
/// Structural copy of the message. Headers get a new dictionary, but the
/// reference and header values are shared (shallow) — this is intentional and relied upon
/// (e.g. a Splitter branch cloning into a shared aggregation list). For an isolated deep copy of
/// the body use .
///
IMessage Clone();
///
/// Deep, isolated copy for checkpoint/replay: like but the
/// is deep-copied so the captured payload is frozen and immune to later in-place mutation.
/// Header values follow (shared) as they carry immutable metadata.
/// Throws if the body cannot be safely deep-copied
/// (it must be immutable, a byte[], or implement ).
///
IMessage Snapshot();
// ── Java-style API (kept forever, default interface methods) ──
/// Java-style: returns Body.
object? getBody() => Body;
/// Java-style: returns Body cast to .
T? getBody()
{
if (Body is null) return default;
if (Body is T typed) return typed;
try { return (T)RouteDecimal.ChangeType(Body, typeof(T)); }
catch { return default; } // conversion failure — return default by design
}
/// Java-style: sets Body.
void setBody(object? value) => Body = value;
/// Java-style: returns ContentType.
string? getContentType() => ContentType;
/// Java-style: sets ContentType.
void setContentType(string? value) => ContentType = value;
/// Java-style: returns header value by key.
object? getHeader(string key) => Headers.TryGetValue(key, out var v) ? v : null;
/// Java-style: returns header value cast to .
T? getHeader(string key) => GetHeader(key);
/// Java-style: sets header value.
void setHeader(string key, object? value) => Headers[key] = value;
/// Java-style: returns Headers dictionary.
IDictionary getHeaders() => Headers;
/// Java-style: removes a header by key.
void removeHeader(string key) => Headers.Remove(key);
/// Java-style: deep copy (alias for Clone).
IMessage copy() => Clone();
}