问题
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