smallrye / smallrye-reactive-messaging

SmallRye Reactive Messaging
http://www.smallrye.io/smallrye-reactive-messaging/
Apache License 2.0
241 stars 179 forks source link

Add multi request to `KafkaRequestReply` #2761

Open Malandril opened 1 month ago

Malandril commented 1 month ago

Purpose

This PR adds a new request type to the KafkaRequestReply so that we can receive multiple replies to a request. This can be useful when you want to send a request, for which multiple consumer groups can answer, or a some service needs to answer with multiple messages. That was not supported with the Uni<Rep> request.

Implementation

This is a first idea to add the feature, in which the KafkaRequestReplyImpl is modified to use a Multi as a base for all operations instead of the Uni. If you think this should be a separate, class or if you have any other idea, do not hesitate.

This adds two new methods requestMulti that returns a Multi<Rep>. I had no idea, for the method names, and we can discuss a better one. The reply.timeout is applied between each reply, and the ReplyFailureHandler is called for each reply, so one failure on a reply will fail the whole operation. I didn't write the doc yet.

If you have any input feel free.

ozangunalp commented 1 month ago

That's a very interesting idea. I'll look later today!

ozangunalp commented 1 month ago

@Malandril Thanks for the tests as well! I've pushed small changes, and exposed a way to complete a pending request.

The upstream consumer request handling is slightly different, but I am unsure of the impact. It was designed to be able to pause the consumer when there aren't any pending requests.