使用ReplyingKafkaTemplate处理多个响应 [英] Handle multiple responses with ReplyingKafkaTemplate

查看:152
本文介绍了使用ReplyingKafkaTemplate处理多个响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现一种回复响应模式,在该模式中,我将消息发布到多个消费者群体都在听的主题.这意味着他们都将获得消息并在回复主题中提交回复.

I'm trying to implement a reply response pattern in which I publish a message to a topic listened to by several consumer groups. That means that they will all get the message as well as submit the response in the reply topic.

问题是因为它们都响应同一条消息,所以仅答复主题中收到的第一条消息.其他的将被丢弃.鉴于我知道我应该在答复主题上得到多少答复(称该号码为n),如何使ReplyingKafkaTemplate等待n个答复然后解决答案?我尝试从 Spring Kafka文档进行推断,但是不太清楚.谢谢.

The problem is because they all respond to the same message, only the first received message in the reply topic shall be answered. The others will be discarded. Given that I know how many responses I should be getting on the reply topic(call that number-n), how can I make ReplyingKafkaTemplate wait for n responses and then resolve the answer? I've tried inferring from the Spring Kafka documentation but could not quite figure it out. Thanks.

推荐答案

该模板仅用于单个请求/答复处理.

That template is strictly for single request/reply processing.

您不能在用例中使用它.

You can't use it for your use case.

使用 KafkaTemplate 和单独的侦听器;您将不得不自己关联答复.

Use a KafkaTemplate and a separate listener; you will have to correlate the replies yourself.

这篇关于使用ReplyingKafkaTemplate处理多个响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆