Struct rdkafka::producer::base_producer::BaseRecord

source ·
pub struct BaseRecord<'a, K: ToBytes + ?Sized = (), P: ToBytes + ?Sized = (), D: IntoOpaque = ()> {
    pub topic: &'a str,
    pub partition: Option<i32>,
    pub payload: Option<&'a P>,
    pub key: Option<&'a K>,
    pub timestamp: Option<i64>,
    pub headers: Option<OwnedHeaders>,
    pub delivery_opaque: D,
}
Expand description

A record for the BaseProducer and ThreadedProducer.

The BaseRecord is a structure that can be used to provide a new record to BaseProducer::send or ThreadedProducer::send. Since most fields are optional, a BaseRecord can be constructed using the builder pattern.

§Examples

This example will create a BaseRecord with no DeliveryOpaque:

let record = BaseRecord::to("topic_name")  // destination topic
    .key(&[1, 2, 3, 4])                    // message key
    .payload("content")                    // message payload
    .partition(5);                         // target partition

The following example will build a similar record, but it will use a number as the DeliveryOpaque for the message:

let record = BaseRecord::with_opaque_to("topic_name", 123) // destination topic and message id
    .key(&[1, 2, 3, 4])                                    // message key
    .payload("content")                                    // message payload
    .partition(5);                                         // target partition

Fields§

§topic: &'a str

Required destination topic.

§partition: Option<i32>

Optional destination partition.

§payload: Option<&'a P>

Optional payload.

§key: Option<&'a K>

Optional key.

§timestamp: Option<i64>

Optional timestamp.

Note that Kafka represents timestamps as the number of milliseconds since the Unix epoch.

§headers: Option<OwnedHeaders>

Optional message headers.

§delivery_opaque: D

Required delivery opaque (defaults to () if not required).

Implementations§

source§

impl<'a, K: ToBytes + ?Sized, P: ToBytes + ?Sized, D: IntoOpaque> BaseRecord<'a, K, P, D>

source

pub fn with_opaque_to( topic: &'a str, delivery_opaque: D, ) -> BaseRecord<'a, K, P, D>

Creates a new record with the specified topic name and delivery opaque.

source

pub fn partition(self, partition: i32) -> BaseRecord<'a, K, P, D>

Sets the destination partition of the record.

source

pub fn payload(self, payload: &'a P) -> BaseRecord<'a, K, P, D>

Sets the payload of the record.

source

pub fn key(self, key: &'a K) -> BaseRecord<'a, K, P, D>

Sets the key of the record.

source

pub fn timestamp(self, timestamp: i64) -> BaseRecord<'a, K, P, D>

Sets the timestamp of the record.

Note that Kafka represents timestamps as the number of milliseconds since the Unix epoch.

source

pub fn headers(self, headers: OwnedHeaders) -> BaseRecord<'a, K, P, D>

Sets the headers of the record.

source§

impl<'a, K: ToBytes + ?Sized, P: ToBytes + ?Sized> BaseRecord<'a, K, P, ()>

source

pub fn to(topic: &'a str) -> BaseRecord<'a, K, P, ()>

Creates a new record with the specified topic name.

Trait Implementations§

source§

impl<'a, K: Debug + ToBytes + ?Sized, P: Debug + ToBytes + ?Sized, D: Debug + IntoOpaque> Debug for BaseRecord<'a, K, P, D>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, K, P, D> Freeze for BaseRecord<'a, K, P, D>
where D: Freeze, K: ?Sized, P: ?Sized,

§

impl<'a, K, P, D> RefUnwindSafe for BaseRecord<'a, K, P, D>

§

impl<'a, K, P, D> Send for BaseRecord<'a, K, P, D>
where P: Sync + ?Sized, K: Sync + ?Sized,

§

impl<'a, K, P, D> Sync for BaseRecord<'a, K, P, D>
where P: Sync + ?Sized, K: Sync + ?Sized,

§

impl<'a, K, P, D> Unpin for BaseRecord<'a, K, P, D>
where D: Unpin, K: ?Sized, P: ?Sized,

§

impl<'a, K, P, D> UnwindSafe for BaseRecord<'a, K, P, D>

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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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<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