SourceRecord

Struct SourceRecord 

Source
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: String

The topic to publish to

§payload: Value

The 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

Source

pub fn new(topic: impl Into<String>, payload: Value) -> Self

Create a new SourceRecord with typed payload

Source

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));
Source

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)?;
Source

pub fn from_number<T: Serialize>( topic: impl Into<String>, number: T, ) -> ConnectorResult<Self>

Create a SourceRecord from a numeric value

Supports integers and floats. The value will be stored as a JSON number.

§Example
let record = SourceRecord::from_number("/metrics/counter", 42);
let record = SourceRecord::from_number("/metrics/temperature", 23.5);
Source

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)?;
Source

pub fn from_bytes(topic: impl Into<String>, data: Vec<u8>) -> Self

Create a SourceRecord from binary data (base64-encoded)

The bytes will be base64-encoded and stored as a JSON object.

§Example
let binary_data = vec![0x48, 0x65, 0x6c, 0x6c, 0x6f]; // "Hello"
let record = SourceRecord::from_bytes("/binary/data", binary_data);
Source

pub fn with_attribute( self, key: impl Into<String>, value: impl Into<String>, ) -> Self

Add an attribute

Source

pub fn with_attributes(self, attrs: HashMap<String, String>) -> Self

Add multiple attributes

Source

pub fn with_key(self, key: impl Into<String>) -> Self

Set the routing key for partitioned topics

Source

pub fn payload(&self) -> &Value

Get the payload as a reference

Trait Implementations§

Source§

impl Clone for SourceRecord

Source§

fn clone(&self) -> SourceRecord

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SourceRecord

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Serialize for SourceRecord

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more