SunilS
SunilS

Reputation: 2288

Kafka - Adding custom headers to record metadata

Does kafka allow adding custom headers to record metadata. Code suggests that it doesn't. Has anyone tried it ?

Upvotes: 3

Views: 2516

Answers (2)

Iskuskov Alexander
Iskuskov Alexander

Reputation: 4375

has included supporting for custom headers since 0.11.0.0 version through KIP-82 - Add Record Headers.

For example, you can use this method:

public ProducerRecord(String topic,
                      Integer partition,
                      K key,
                      V value,
                      Iterable<Header> headers)

See also related questions:

  1. Adding Custom Headers in Kafka Message
  2. Header information in kafka producer API

Upvotes: 3

OneCricketeer
OneCricketeer

Reputation: 191844

Yes, the Java API has headers

public ProducerRecord(java.lang.String topic,
                          java.lang.Integer partition,
                          java.lang.Long timestamp,
                          K key,
                          V value,
                          java.lang.Iterable headers)

Creates a record with a specified timestamp 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
    timestamp - The timestamp of the record, in milliseconds since epoch. If null, the producer will assign the timestamp using System.currentTimeMillis().
    key - The key that will be included in the record
    value - The record contents
    headers - the headers that will be included in the record

Upvotes: 2

Related Questions