Search code examples
apache-kafkaapache-kafka-streams

ProcessorContext#header() is Empty


We have kafka stream application. Producer is adding header in kafka message before sending it to Kafka Streaming application.

In Kafka streaming app we are using AbstractProcessor and context.forward(null, Optional.of(event)); to forward message to another topic.

But header is getting lossed. I want header to be as it is from input message to output topic.

ProcessorContext Interface. headers() method says Returns the headers of the current input record but it's empty in my case though I am sending message with header.

     * Returns the headers of the current input record; could be null if it is not available
     * @return the headers
     */
    Headers headers();

Kafka Stream API Version: 2.3.1


Solution

  • context.headers() shoud be called with in process() if using a Processor or transform() if using a Transformer.