Skip to content
Advertisement

Spring Webflux – reactive repository saveAll(Iterable) vs saveAll(Publisher)

Small question about the webflux reactive repository, especially about the methods saveAll Flux saveAll(Iterable var1); versus Flux saveAll(Publisher var1);

Wanted to compare, I wrote the following:

JavaScript

In terms of “correctness” both codes are doing what is expected. Everything is persisted successfully.

But in terms of performance, reactive paradigm, IO Utilisations to DB, Netty Core usage, what is the “best” solution and why please?

Thank you

Advertisement

Answer

It all depends on what objects you currently have. If you have a Flux of objects, use the saveAll method that takes a Publisher. If you have the actual Collection of objects, use the saveAll method that takes an Iterable.

As an example, if you look at the implementation SimpleReactiveCassandraRepository the implementation of saveAll that takes an Iterable just wraps it in a Flux and delegates to the saveAll method that accepts a Flux

JavaScript

As a result, there should no difference in terms of IO utilisation or netty core usage. Also, both follow the reactive paradigm.

SimpleReactiveCassandraRepository Code

Advertisement