0

I am fairly new to WebFlux and I am looking for what seems to be a pretty normal usage pattern. Basically what I have is a Spring Controller which returns a Flux< A > (where A is a row fetched from the DB using R2DBC). I want to do an async operation on each received object (for instance I want to send a push notification for each object, for which I also need to make a call to the DB for the users push token and then send the push). The operations should be done asynchronously, so the API end-users receive their data with no delay. Is there some pattern for this already?

Veles
  • 1,512
  • 4
  • 14
  • 28
  • Is this for a controller? You can just use map and return the Flux. – 123 Apr 14 '20 at 17:30
  • The operation I am doing for each item could take a while, map is synchronous so it is not an option. – Veles Apr 14 '20 at 21:05
  • You need to use flatmap operator, add code sample for more details. – Yauhen Balykin Apr 14 '20 at 21:36
  • 2
    @Veles "The operations should be done asynchronously, so the API end-users receive their data with no delay" - do you want a "fire and forget" type approach, or something else? A code sample would help tremendously here. – Michael Berry Apr 14 '20 at 21:54
  • If you need fire-and-forget, this might help: https://stackoverflow.com/a/57569541/6051176 – Martin Tarjányi Apr 15 '20 at 08:05
  • Yes, thats it Martin :-) Please add it as the answer, I will mark it. – Veles Apr 15 '20 at 10:06
  • Does this answer your question? [Fire and forget with reactor](https://stackoverflow.com/questions/57566465/fire-and-forget-with-reactor) – Didier L Jul 20 '22 at 14:33

0 Answers0