Alex
Alex

Reputation: 859

Kafka Producer Timestamp

I'm having trouble understanding the ProducerRecord.

Previously I was constructing the ProducerRecord like this:

new ProducerRecord<String, String>("my-topic", "key", "value")

I'd like to pass in a timestamp additionally so I decided to check the docs and found out that the constructor indeed allows passing a timestamp. But it also required specifying a partition like this:

new ProducerRecord(String topic,
              Integer partition,
              Long timestamp,
              K key,
              V value)

I'm confused about what to pass as the partition parameter since the previous constructor I used was handling it for me.

Upvotes: 1

Views: 3602

Answers (1)

Vijendra Kumar Kulhade
Vijendra Kumar Kulhade

Reputation: 2255

You can use still this constructor without any problem. You will have pass partition null in this constructor and still DefaultPartitioner will take care about the partitioner assignment. Just name sure that you are using new KafkaProducer API. Timestamp doesn't work for old scala based producer.

Upvotes: 9

Related Questions