Reputation: 63
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 ?
Upvotes: 1
Views: 1402
Reputation: 1
If you are publishing from a producer and subscribing to an individual listener based on any criteria, and that single listener writes back to an individual response topic, you can simply configure your producer to listen back from an array list of topics
String[] requestReplyTopics = {"Volvo", "BMW", "Ford", "Mazda"};
@Bean
public KafkaMessageListenerContainer<String, Model> replyContainer(ConsumerFactory<String, Model> cf) {
ContainerProperties containerProperties = new ContainerProperties(requestReplyTopic);
return new KafkaMessageListenerContainer<>(cf, containerProperties);
}
Upvotes: 0
Reputation: 174554
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).
Upvotes: 3