Reputation: 41
I am trying to access various KafkaHeaders properties in my spring kafka listener:
Here is my code for getting the KafkaListenerContainerFactory :
public KafkaListenerContainerFactory<ConcurrentMessageListener<String,GenericRecord>> kafkaListenerContainerFactory(final KafkaProperties kafkaProperties){
final ConcurrentKafkaListenerContainerFactory<String,GenericRecord> factory=new ConcurrentKafkaListenerContainerFactory<>();
factory.setBatchErrorHandler(new BatchLoggingErrorHandler());
factory.setBatchListener(true);
return factory;
}
My listener code:
@KafkaListener(topic="testTopic",groupId="testGroupId"){
public void consumeNotification(@Payload Request request, @Header(KafkaHeaders.RECORD_METADATA) RecordMetadata recordMetaData){
}
But I am getting exception in my Listener:
Missing header 'kafka_recordMetadata' for method parameterType[class org.apache.kafka.clients.producer.RecordMetadata]
For all header properties, I am getting this error...Is it something to do with the producer?
All the properties in KafkaHeaders are creating issues for me. Everything is throwing MissingHeader error.
Upvotes: 0
Views: 1314
Reputation: 121542
See docs for supported headers: https://docs.spring.io/spring-kafka/docs/current/reference/html/#consumer-record-metadata.
The KafkaHeaders.RECORD_METADATA
was never there. More over the RecordMetadata
is a produce side object: org.apache.kafka.clients.producer.RecordMetadata
.
Therefore it is not clear what drives you to do whatever you have in your code so far...
Upvotes: 1