pub struct ProducerRecord<K, V> { /* private fields */ }Expand description
A key/value pair to be sent to Kafka. This consists of a topic name to which the record is being sent, an optional partition number, and an optional key and value.
If a valid partition number is specified that partition will be used when sending the record. If no partition is specified but a key is present a partition will be chosen using a hash of the key. If neither key nor partition is present a partition will be assigned in a round-robin fashion. Note that partition numbers are 0-indexed.
The record also has an associated timestamp. If the user did not provide a timestamp, the producer will stamp the record with its current time. The timestamp eventually used by Kafka depends on the timestamp type configured for the topic.
- If the topic is configured to use
CreateTime, the timestamp in the producer record will be used by the broker. - If the topic is configured to use
LogAppendTime, the timestamp in the producer record will be overwritten by the broker with the broker local time when it appends the message to its log.
In either case, the timestamp that has actually been used will be returned to the user
in RecordMetadata.
Implementations§
Source§impl<K, V> ProducerRecord<K, V>
impl<K, V> ProducerRecord<K, V>
Sourcepub fn with_options(
options: ProducerRecordOptions<K, V>,
) -> Result<Self, LocalIllegalArgumentError>
pub fn with_options( options: ProducerRecordOptions<K, V>, ) -> Result<Self, LocalIllegalArgumentError>
Creates a record with a specified timestamp to be sent to a specified topic and partition
§Arguments
options- The topic the record will be appended to, the partition to which the record should be sent, the timestamp of the record in milliseconds since epoch (ifNone, the producer will assign the timestamp using the system clock), the key and the headers that will be included in the record, and the record contents
§Errors
LocalIllegalArgumentErrorif the timestamp or the partition is negative.
§Translation notes
Java’s ProducerRecord(String, Integer, Long, K, V, Iterable<Header>):
its six parameters are the fields of ProducerRecordOptions.
Sourcepub fn with_partition_timestamp_key(
topic: String,
partition: Option<i32>,
timestamp: Option<i64>,
key: Option<K>,
value: Option<V>,
) -> Result<Self, LocalIllegalArgumentError>
pub fn with_partition_timestamp_key( topic: String, partition: Option<i32>, timestamp: Option<i64>, key: Option<K>, value: Option<V>, ) -> Result<Self, LocalIllegalArgumentError>
Creates a record with a specified timestamp to be sent to a specified topic and partition
§Arguments
topic- The topic the record will be appended topartition- The partition to which the record should be senttimestamp- The timestamp of the record, in milliseconds since epoch. If None, the producer will assign the timestamp using System.currentTimeMillis().key- The key that will be included in the recordvalue- The record contents
§Errors
LocalIllegalArgumentErrorif the timestamp or the partition is negative.
Sourcepub fn with_partition_key_headers(
topic: String,
partition: Option<i32>,
key: Option<K>,
value: Option<V>,
headers: RecordHeaders,
) -> Result<Self, LocalIllegalArgumentError>
pub fn with_partition_key_headers( topic: String, partition: Option<i32>, key: Option<K>, value: Option<V>, headers: RecordHeaders, ) -> Result<Self, LocalIllegalArgumentError>
Creates a record to be sent to a specified topic and partition
§Arguments
topic- The topic the record will be appended topartition- The partition to which the record should be sentkey- The key that will be included in the recordvalue- The record contentsheaders- The headers that will be included in the record
§Errors
LocalIllegalArgumentErrorif the partition is negative.
Sourcepub fn with_partition_key(
topic: String,
partition: Option<i32>,
key: Option<K>,
value: Option<V>,
) -> Result<Self, LocalIllegalArgumentError>
pub fn with_partition_key( topic: String, partition: Option<i32>, key: Option<K>, value: Option<V>, ) -> Result<Self, LocalIllegalArgumentError>
Creates a record to be sent to a specified topic and partition
§Arguments
topic- The topic the record will be appended topartition- The partition to which the record should be sentkey- The key that will be included in the recordvalue- The record contents
§Errors
LocalIllegalArgumentErrorif the partition is negative.
Sourcepub fn with_key(topic: String, key: Option<K>, value: Option<V>) -> Self
pub fn with_key(topic: String, key: Option<K>, value: Option<V>) -> Self
Create a record to be sent to Kafka
§Arguments
topic- The topic the record will be appended tokey- The key that will be included in the recordvalue- The record contents
Sourcepub fn new(topic: String, value: Option<V>) -> Self
pub fn new(topic: String, value: Option<V>) -> Self
Create a record with no key
§Arguments
topic- The topic this record should be sent tovalue- The record contents
Sourcepub fn headers(&self) -> &RecordHeaders
pub fn headers(&self) -> &RecordHeaders
Returns the headers.
Trait Implementations§
Source§impl<K: Clone, V: Clone> Clone for ProducerRecord<K, V>
impl<K: Clone, V: Clone> Clone for ProducerRecord<K, V>
Source§fn clone(&self) -> ProducerRecord<K, V>
fn clone(&self) -> ProducerRecord<K, V>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl<K: Eq, V: Eq> Eq for ProducerRecord<K, V>
Auto Trait Implementations§
impl<K, V> Freeze for ProducerRecord<K, V>
impl<K, V> RefUnwindSafe for ProducerRecord<K, V>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for ProducerRecord<K, V>
impl<K, V> Sync for ProducerRecord<K, V>
impl<K, V> Unpin for ProducerRecord<K, V>
impl<K, V> UnsafeUnpin for ProducerRecord<K, V>where
K: UnsafeUnpin,
V: UnsafeUnpin,
impl<K, V> UnwindSafe for ProducerRecord<K, V>where
K: UnwindSafe,
V: UnwindSafe,
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,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.