pub struct MessageBuilder { /* private fields */ }Expand description
Builder for Message. Collapses the historical
new / with_id / from_value / without_change_capture four-way
constructor split into a single fluent shape.
use dataflow_rs::Message;
use serde_json::json;
// Minimal: serde_json payload, default UUID id, capture on.
let m = Message::builder()
.payload_json(&json!({"order": {"total": 1500}}))
.build();
assert!(m.id().len() > 0);
assert!(m.capture_changes());Implementations§
Source§impl MessageBuilder
impl MessageBuilder
Sourcepub fn new() -> Self
pub fn new() -> Self
Create an empty builder. Equivalent to MessageBuilder::default.
Sourcepub fn id(self, id: impl Into<String>) -> Self
pub fn id(self, id: impl Into<String>) -> Self
Caller-supplied id (typically a correlation id from upstream). Defaults to a freshly-generated UUID v7.
Sourcepub fn payload(self, payload: Arc<OwnedDataValue>) -> Self
pub fn payload(self, payload: Arc<OwnedDataValue>) -> Self
Already-owned payload Arc — zero serde_json walk, refcount-only
share. Mutually exclusive with Self::payload_json; whichever is
called last wins.
Sourcepub fn payload_json(self, payload: &JsonValue) -> Self
pub fn payload_json(self, payload: &JsonValue) -> Self
Construct the payload from a serde_json::Value. Goes through the
OwnedDataValue::from(&Value) bridge (one deep walk).
Sourcepub fn data(self, data: OwnedDataValue) -> Self
pub fn data(self, data: OwnedDataValue) -> Self
Seed context.data.
Replaces the empty Object that Self::build would otherwise install;
the other two root fields are unaffected. Seeding records no audit-trail
entry and no Change — it is initial state, not a mutation.
Keys are taken literally: unlike
crate::engine::utils::set_nested_value, a key containing . stays a
single key and a leading # is not stripped.
A non-Object value is ignored, preserving the crate-wide invariant
that the three root fields are always objects. Calling this twice keeps
the last value.
use dataflow_rs::Message;
use serde_json::json;
let m = Message::builder().data_json(&json!({"order": {"total": 1500}})).build();
assert_eq!(m.data()["order"]["total"], json!(1500).into());Sourcepub fn data_json(self, data: &JsonValue) -> Self
pub fn data_json(self, data: &JsonValue) -> Self
Self::data from a serde_json::Value (one OwnedDataValue::from
deep walk).
Sourcepub fn metadata(self, metadata: OwnedDataValue) -> Self
pub fn metadata(self, metadata: OwnedDataValue) -> Self
Seed context.metadata — request headers, correlation ids, routing
hints.
Engine::process_message adds processed_at and engine_version on top
of whatever is seeded here; a seeded channel key is overwritten by
process_message_for_channel. Same literal-key and non-object rules as
Self::data.
use dataflow_rs::Message;
use serde_json::json;
let m = Message::builder().metadata_json(&json!({"source": "api"})).build();
assert_eq!(m.metadata()["source"], json!("api").into());Sourcepub fn metadata_json(self, metadata: &JsonValue) -> Self
pub fn metadata_json(self, metadata: &JsonValue) -> Self
Self::metadata from a serde_json::Value.
Sourcepub fn temp_data(self, temp_data: OwnedDataValue) -> Self
pub fn temp_data(self, temp_data: OwnedDataValue) -> Self
Seed context.temp_data — scratch space for intermediate task output.
Same literal-key and non-object rules as Self::data.
use dataflow_rs::Message;
use serde_json::json;
let m = Message::builder().temp_data_json(&json!({"scratch": 1})).build();
assert_eq!(m.temp_data()["scratch"], json!(1).into());Sourcepub fn temp_data_json(self, temp_data: &JsonValue) -> Self
pub fn temp_data_json(self, temp_data: &JsonValue) -> Self
Self::temp_data from a serde_json::Value.
Sourcepub fn routing_bucket(self, bucket: u8) -> Self
pub fn routing_bucket(self, bucket: u8) -> Self
Routing bucket 0..=99 for crate::Workflow::rollout matching.
Values >= 100 are clamped to 99, keeping the builder infallible like
the rest of its methods. A message with no bucket is admitted by every
workflow, split or not.
use dataflow_rs::Message;
assert_eq!(Message::builder().routing_bucket(7).build().routing_bucket(), Some(7));
assert_eq!(Message::builder().routing_bucket(200).build().routing_bucket(), Some(99));
assert_eq!(Message::builder().build().routing_bucket(), None);Sourcepub fn capture_changes(self, on: bool) -> Self
pub fn capture_changes(self, on: bool) -> Self
When false, built-in functions skip per-write Change capture —
audit-trail entries are still recorded but their changes list is
empty. Defaults to true.