I'm still quite new to the Lagom framework and I'm seeking the best way to fetch all users of my distributed application.
In my app, I have a user service working on Cassandra DB. So to select all users I followed the Lagom Online Auction example application, in UserServiceImpl.java:
//...
@Override
public ServiceCall<NotUsed, PSequence<User>> getUsers() {
// Note this should never make production....
return req -> currentIdsQuery.currentPersistenceIds()
.filter(id -> id.startsWith("UserEntity"))
.mapAsync(4, id ->
entityRef(id.substring(10))
.ask(UserCommand.GetUser.INSTANCE))
.filter(Optional::isPresent)
.map(Optional::get)
.runWith(Sink.seq(), mat)
.thenApply(TreePVector::from);
}
//...
I also checked this Question on SO
It is clear that the idea of the read-side works with one instance of user service. But, in the production environment, I should have many instances of the same service may run on multiple nodes. In these case, I think that each service should have its own DB.
So my question is: Does the read-side logic can cover only all users per service instance or it should cover all users of all service instances?
Also, is there any other solution to get all users of all service instances?
Many thanks.