Search code examples
apache-kafkakafka-consumer-apispring-kafka

Configuring ReplyingKafkaTemplate for getting the responses from multiple topics


I have a requirement where I must use the synchronous request-reply pattern with Kafka, hence I am using ReplyingKafkaTemplate for the same.

As a part of implementation, there is a producer which is pushing a request message on one topic(input-message-topic1) but in return I am expecting responses from two topics(output-message-topic1 and output-message-topic2) which I have to aggregate and process further.

Question : Is it possible to implement the above scenario with ReplyingKafkaTemplate / AggregatingReplyingKafkaTemplate or any other implementation which uses synchronous request-reply pattern with Kafka ?


Solution

  • Yes, the AggregatingReplyingKafkaTemplate will do this; just configure its listener container to consume from both topics; the replies must contain the correlation id header (used to aggregate).