配置 ReplyingKafkaTemplate 以获取来自多个主题的响应 [英] Configuring ReplyingKafkaTemplate for getting the responses from multiple topics
问题描述
我有一个要求,我必须对 Kafka 使用同步请求-回复模式,因此我使用 ReplyingKafkaTemplate.
I have a requirement where I must use the synchronous request-reply pattern with Kafka, hence I am using ReplyingKafkaTemplate for the same.
作为实现的一部分,有一个生产者正在推送关于一个主题的请求消息(input-message-topic1),但作为回报,我期待来自两个主题的响应(output-message-topic1 和 output-message-topic2),我必须进一步汇总和处理.
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.
问题:是否可以使用 ReplyingKafkaTemplate/AggregatingReplyingKafkaTemplate 或任何其他使用 Kafka 同步请求-回复模式的实现来实现上述场景?
Question : Is it possible to implement the above scenario with ReplyingKafkaTemplate / AggregatingReplyingKafkaTemplate or any other implementation which uses synchronous request-reply pattern with Kafka ?
推荐答案
是的,AggregatingReplyingKafkaTemplate
会做到这一点;只需将其侦听器容器配置为从两个主题中消费即可;回复必须包含相关 ID 标头(用于聚合).
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).
这篇关于配置 ReplyingKafkaTemplate 以获取来自多个主题的响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!