public class ProducerRecord<K,V>
extends java.lang.Object
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.
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.
CreateTime
,
the timestamp in the producer record will be used by the broker.
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 of the cases above, the timestamp that has actually been used will be returned to user in
RecordMetadata
Constructor and Description |
---|
ProducerRecord(java.lang.String topic,
java.lang.Integer partition,
K key,
V value)
Creates a record to be sent to a specified topic and partition
|
ProducerRecord(java.lang.String topic,
java.lang.Integer partition,
K key,
V value,
java.lang.Iterable<Header> headers)
Creates a record to be sent to a specified topic and partition
|
ProducerRecord(java.lang.String topic,
java.lang.Integer partition,
java.lang.Long timestamp,
K key,
V value)
Creates a record with a specified timestamp to be sent to a specified topic and partition
|
ProducerRecord(java.lang.String topic,
java.lang.Integer partition,
java.lang.Long timestamp,
K key,
V value,
java.lang.Iterable<Header> headers)
Creates a record with a specified timestamp to be sent to a specified topic and partition
|
ProducerRecord(java.lang.String topic,
K key,
V value)
Create a record to be sent to Kafka
|
ProducerRecord(java.lang.String topic,
V value)
Create a record with no key
|
public ProducerRecord(java.lang.String topic, java.lang.Integer partition, java.lang.Long timestamp, K key, V value, java.lang.Iterable<Header> headers)
topic
- The topic the record will be appended topartition
- The partition to which the record should be senttimestamp
- The timestamp of the recordkey
- The key that will be included in the recordvalue
- The record contentsheaders
- the headers that will be included in the recordpublic ProducerRecord(java.lang.String topic, java.lang.Integer partition, java.lang.Long timestamp, K key, V value)
topic
- The topic the record will be appended topartition
- The partition to which the record should be senttimestamp
- The timestamp of the recordkey
- The key that will be included in the recordvalue
- The record contentspublic ProducerRecord(java.lang.String topic, java.lang.Integer partition, K key, V value, java.lang.Iterable<Header> headers)
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 recordpublic ProducerRecord(java.lang.String topic, java.lang.Integer partition, K key, V value)
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 contentspublic ProducerRecord(java.lang.String topic, K key, V value)
topic
- The topic the record will be appended tokey
- The key that will be included in the recordvalue
- The record contentspublic ProducerRecord(java.lang.String topic, V value)
topic
- The topic this record should be sent tovalue
- The record contentspublic java.lang.String topic()
public Headers headers()
public K key()
public V value()
public java.lang.Long timestamp()
public java.lang.Integer partition()
public java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object