Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the use of Header in Kafka Processor API?

I am learning Kafka Processor API and find one method headers in ProcessorContext.

headers​()

Returns the headers of the current input record; could be null if it is not available

What is the use of this method?

In docs only one line is written:

Returns the headers of the current input record; could be null if it is not available

Can i perform some operation on this like add?

like image 716
Mohit Singh Avatar asked Jan 27 '26 11:01

Mohit Singh


1 Answers

A header is some sort of metadata that can be appended to each message. Headers can be used in various scenarios like appending information that can be used when filtering records etc.


You can access messages' metadata through Processor API and more precisely process(), transform() and transformValues(). For example, in order to add a header to a record, the following will do the trick:

public void process(String key, String value) {

    // add a header to the elements
    context().headers().add.("key", "value")
}
like image 58
Giorgos Myrianthous Avatar answered Jan 29 '26 12:01

Giorgos Myrianthous