I want to execute non-blocking database queries through Spring Data accessing a MongoDB using MongoDB's Async Client API.
So far I've only seen the possibility to return a
java.util.concurrent.Future
java.util.concurrent.CompletableFuture
org.springframework.util.concurrent.ListenableFuture
and annotate the query method with @Async
, e.g.
public interface UserRepo extends Repository<User, Long> { @Async ListenableFuture<User> findByName(String name); }
but the documentation clearly states that the actual [...] query execution will occur in a task that has been submitted to a Spring TaskExecutor
. So it's not really non-blocking but just decoupling my thread using a thread pool which doesn't scale very well.
Therefore my question:
How to execute the queries in non-blocking mode using the MongoDB Async Driver's NIO Features?
The only workaround I see so far is to get rid of Spring Data and implement the database queries by my own using the Mongo Async Driver API. But hopefully I'm just missing something and there is a straigth-forward answer out there. ;)