Maxime
Maxime

Reputation: 191

How to throttle throughput of a Quarkus reactive messaging stream

I'm using Quarkus 1.13.7 and smallrye reactive messaging to consume a Kafka topic and for each message making an HTTP request to an external component that impose a throughput limit of requests (eg. : 30 requests/second).

The idea is to call the external component as fast as possible to reach its maximum capacity but blocking the stream when the throughput limit is reached in a defined time window. Reaching maximum capacity would require to add concurrency using @Blocking(ordered = false) annotation, as a unique request can be a bit long.

But how I can throttle the stream when the limit throughput is reached ?

Is there a way to throttle a Multi stream, for example adding a mutiny operator on that stream, like what exists in Akka Stream lib ?

I know Akka is interoperable with Mutiny using Java 9 Reactive Streams interface but as Akka is not fully open source any more and as I would avoid thread switch complexity between Akka thread pool and Quarkus thread pool, this is not a option.

Upvotes: 0

Views: 691

Answers (1)

Ozan Günalp
Ozan Günalp

Reputation: 474

I think the easiest way to achieve this would be to assign a custom worker pool with max concurrency to your @Blocking annotation. It is described here: http://smallrye.io/smallrye-reactive-messaging/4.7.0/concepts/blocking/

Upvotes: 0

Related Questions