org.apache.kafka.clients.producer
Class ProducerRecord<K,V>

java.lang.Object
  extended by org.apache.kafka.clients.producer.ProducerRecord<K,V>

public final class ProducerRecord<K,V>
extends java.lang.Object

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.


Constructor Summary
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, 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
 
Method Summary
 K key()
          The key (or null if no key is specified)
 java.lang.Integer partition()
          The partition to which the record will be sent (or null if no partition was specified)
 java.lang.String topic()
          The topic this record is being sent to
 java.lang.String toString()
           
 V value()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ProducerRecord

public 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

Parameters:
topic - The topic the record will be appended to
partition - The partition to which the record should be sent
key - The key that will be included in the record
value - The record contents

ProducerRecord

public ProducerRecord(java.lang.String topic,
                      K key,
                      V value)
Create a record to be sent to Kafka

Parameters:
topic - The topic the record will be appended to
key - The key that will be included in the record
value - The record contents

ProducerRecord

public ProducerRecord(java.lang.String topic,
                      V value)
Create a record with no key

Parameters:
topic - The topic this record should be sent to
value - The record contents
Method Detail

topic

public java.lang.String topic()
The topic this record is being sent to


key

public K key()
The key (or null if no key is specified)


value

public V value()
Returns:
The value

partition

public java.lang.Integer partition()
The partition to which the record will be sent (or null if no partition was specified)


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object