I'm sending a message to Kafka using the ReplyingKafkaTemplate
and it's sending the message with a kafka_correlationId
. However, when it hits my @KafkaListener
method and forwards it to a reply topic, the headers are lost.
How do I preserve the kafka headers?
Here's my method signature:
@KafkaListener(topics = "input")
@SendTo("reply")
public List<CustomOutput> consume(List<CustomInput> inputs) {
... /* some processing */
return outputs;
}
I've created a ProducerInterceptor
so I can see what headers are being sent from the ReplyingKafkaTemplate
, as well as from the @SendTo
annotation. From that, another strange thing is that the ReplyingKafkaTemplate
is not adding the documented kafka_replyTopic
header to the message.
Here's how the ReplyingKafkaTemplate
is configured:
@Bean
public KafkaMessageListenerContainer<Object, Object> replyContainer(ConsumerFactory<Object, Object> cf) {
ContainerProperties containerProperties = new ContainerProperties(requestReplyTopic);
return new KafkaMessageListenerContainer<>(cf, containerProperties);
}
@Bean
public ReplyingKafkaTemplate<Object, Object, Object> replyingKafkaTemplate(ProducerFactory<Object, Object> pf, KafkaMessageListenerContainer<Object, Object> container) {
return new ReplyingKafkaTemplate<>(pf, container);
}
I'm not sure if this is relevant, but I've added Spring Cloud Sleuth as a dependency as well, and the span/trace headers are there when I'm sending messages, but new ones are generated when a message is forwarded.