Struct rdkafka::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>
impl<'a, K: ToBytes + ?Sized, P: ToBytes + ?Sized, D: IntoOpaque> BaseRecord<'a, K, P, D>
sourcepub fn with_opaque_to(
topic: &'a str,
delivery_opaque: D,
) -> BaseRecord<'a, K, P, D>
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.
sourcepub fn partition(self, partition: i32) -> BaseRecord<'a, K, P, D>
pub fn partition(self, partition: i32) -> BaseRecord<'a, K, P, D>
Sets the destination partition of the record.
sourcepub fn payload(self, payload: &'a P) -> BaseRecord<'a, K, P, D>
pub fn payload(self, payload: &'a P) -> BaseRecord<'a, K, P, D>
Sets the payload of the record.
sourcepub fn key(self, key: &'a K) -> BaseRecord<'a, K, P, D>
pub fn key(self, key: &'a K) -> BaseRecord<'a, K, P, D>
Sets the key of the record.
sourcepub fn timestamp(self, timestamp: i64) -> BaseRecord<'a, K, P, D>
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.
sourcepub fn headers(self, headers: OwnedHeaders) -> BaseRecord<'a, K, P, D>
pub fn headers(self, headers: OwnedHeaders) -> BaseRecord<'a, K, P, D>
Sets the headers of the record.