SpringSpring Kafka Advanced
How do you implement request-reply pattern with Spring Kafka?
Reference answer
Spring Kafka's ReplyingKafkaTemplate implements request-reply. Producer sends message with a reply topic header (KafkaHeaders.REPLY_TOPIC). Consumer processes and sends response to the reply topic. The template correlates by a unique correlation ID in message headers. Configure: @Bean ReplyingKafkaTemplate<K,V,R> replyingTemplate(ProducerFactory<K,V> pf, KafkaMessageListenerContainer<K,R> container). The request call blocks until reply arrives (or timeout). This synchronous-over-async pattern is useful for RPC-style calls over Kafka without an additional HTTP layer.
Expected key concepts: ReplyingKafkaTemplate, reply topic, KafkaHeaders.REPLY_TOPIC, correlation ID, headers, request-reply, RPC, synchronous-over-async, blocking, timeout