Handle multiple responses with ReplyingKafkaTemplate

Deadly 提交于 2021-01-29 13:00:27

问题


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.

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.


回答1:


That template is strictly for single request/reply processing.

You can't use it for your use case.

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



来源:https://stackoverflow.com/questions/55168639/handle-multiple-responses-with-replyingkafkatemplate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!