Kafka

ProducerRecord API

ProducerRecord API

 

ProducerRecord specifies a key/value pair to be sent to Kafka cluster to create a record with the partition using the following syntax -

 

public ProducerRecord (string topic, int partition, k key, v value)

 

Here, topic corresponds to the topic name defined by the user

Partition refers to partition count

Key is the value included in the record

Value refers to record contents

 

Here’s the syntax used to create a record with key, value pairs and without partition using the ProducerRecord class constructor -

 

public ProducerRecord (string topic, k key, v value)

 

Here’s the syntax used to create a record without partition and key -

 

public ProducerRecord (string topic, v value)

 

Some examples of ProducerRecord class methods are listed below -

 

  • public string topic()

To add a topic to the record

  • partition()

Add partition count to the record 

  • public K key()

The key value to be included in the record. In case of no key, NULL will be returned here which means that the data is sent without the key. 

  • public V value()

To record contents 


 

Top course recommendations for you

    DevOps Landscape
    2 hrs
    Beginner
    2.2K+ Learners
    4.51  (71)
    Joins in SQL
    2 hrs
    Beginner
    8K+ Learners
    4.47  (281)
    Introduction to Firewall
    1 hrs
    Beginner
    20.6K+ Learners
    4.55  (1072)
    Design Thinking for Beginners
    1 hrs
    Beginner
    11.7K+ Learners
    4.41  (781)
    Database Management System
    1 hrs
    Beginner
    29.4K+ Learners
    4.44  (2037)
    Operational Excellence and Critical Thinking
    1 hrs
    Beginner
    5.6K+ Learners
    4.49  (263)
    .NET Fundamentals
    2 hrs
    Beginner
    19.5K+ Learners
    4.46  (1006)
    .NET OOPS
    1 hrs
    Beginner
    5.2K+ Learners
    4.55  (223)
    Python Practice Codes
    1 hrs
    Beginner
    6.7K+ Learners
    4.32  (215)
    VLOOKUP in Excel
    1 hrs
    Beginner
    34K+ Learners
    4.6  (1342)