pub struct SourceRecord {
pub topic: String,
pub payload: Value,
pub attributes: HashMap<String, String>,
pub key: Option<String>,
}Expand description
Record passed from source connectors (External System → Danube)
Source connectors emit typed data as serde_json::Value. The runtime handles
schema-based serialization before sending to Danube.
Fields§
§topic: StringThe topic to publish to
payload: ValueThe message payload (typed data, not bytes)
attributes: HashMap<String, String>Optional message attributes/headers
key: Option<String>Optional routing key for partitioned topics (will be used when Danube supports it)
Implementations§
Source§impl SourceRecord
impl SourceRecord
Sourcepub fn new(topic: impl Into<String>, payload: Value) -> Self
pub fn new(topic: impl Into<String>, payload: Value) -> Self
Create a new SourceRecord with typed payload
Sourcepub fn from_string(topic: impl Into<String>, payload: impl Into<String>) -> Self
pub fn from_string(topic: impl Into<String>, payload: impl Into<String>) -> Self
Create a SourceRecord from a string payload
Use this for text-based data like log messages, plain text, or string values.
§Example
let record = SourceRecord::from_string("/logs/application", "Server started successfully");
let record = SourceRecord::from_string("/events/notifications", format!("User {} logged in", user_id));Sourcepub fn from_json<T: Serialize>(
topic: impl Into<String>,
data: T,
) -> ConnectorResult<Self>
pub fn from_json<T: Serialize>( topic: impl Into<String>, data: T, ) -> ConnectorResult<Self>
Create a SourceRecord from any JSON-serializable object
Use this for structured data types that implement Serialize.
The data will be converted to serde_json::Value.
§Example
#[derive(Serialize)]
struct OrderEvent {
order_id: String,
amount: f64,
currency: String,
}
let order = OrderEvent {
order_id: "ORD-12345".to_string(),
amount: 99.99,
currency: "USD".to_string(),
};
let record = SourceRecord::from_json("/orders/created", &order)?;Sourcepub fn from_number<T: Serialize>(
topic: impl Into<String>,
number: T,
) -> ConnectorResult<Self>
pub fn from_number<T: Serialize>( topic: impl Into<String>, number: T, ) -> ConnectorResult<Self>
Sourcepub fn from_avro<T: Serialize>(
topic: impl Into<String>,
data: T,
) -> ConnectorResult<Self>
pub fn from_avro<T: Serialize>( topic: impl Into<String>, data: T, ) -> ConnectorResult<Self>
Create a SourceRecord from an Avro-compatible struct
In Danube, Avro schemas use JSON serialization with schema validation.
This is an alias for from_json() for clarity when working with Avro schemas.
§Example
#[derive(Serialize)]
struct UserEvent {
user_id: String,
action: String,
timestamp: i64,
}
let event = UserEvent { ... };
let record = SourceRecord::from_avro("/events/users", &event)?;Sourcepub fn with_attribute(
self,
key: impl Into<String>,
value: impl Into<String>,
) -> Self
pub fn with_attribute( self, key: impl Into<String>, value: impl Into<String>, ) -> Self
Add an attribute
Sourcepub fn with_attributes(self, attrs: HashMap<String, String>) -> Self
pub fn with_attributes(self, attrs: HashMap<String, String>) -> Self
Add multiple attributes
Trait Implementations§
Source§impl Clone for SourceRecord
impl Clone for SourceRecord
Source§fn clone(&self) -> SourceRecord
fn clone(&self) -> SourceRecord
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SourceRecord
impl Debug for SourceRecord
Auto Trait Implementations§
impl Freeze for SourceRecord
impl RefUnwindSafe for SourceRecord
impl Send for SourceRecord
impl Sync for SourceRecord
impl Unpin for SourceRecord
impl UnwindSafe for SourceRecord
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request