Hello,
I am writing an Akka server that uses Redis for persistence. The scala-redis library is a blocking library, and I know Akka actors are generally supposed to do async IO.
I studied the Redis durable mailbox code (and emulated it) but I wonder if that code is too specialized for me to use for general purpose database access and I was hoping there were some best practices around this.
What I have now (following the durable mailbox example) is that for a particular Repository (like UserRepository) in my system I will have a single actor that reads and writes data for that entity. So each entity will be represented by a RepositoryActor that owns an instance of an appropriate Repository which does the actual DB communication.
The way I have it written each Repository gets its own RedisClientPool, but I'm not doing anything with futures to keep the Redis calls from blocking so I think it is wrong. Also, I feel like I should probably model each Repository actor behind a router so that load can be distributed among a set of workers, but again I'm not certain how (or if) to share the client pool with the workers, or if the client pool should be shared with all workers of all repository actors via some (ActorSystem scoped) singleton, or just how to utilize the client pool to avoid blocking whatever reactor loop Akka uses.
Is anyone aware of any code on Github that might demonstrate a reasonable pattern for modeling sane database access via Akka Actors with a blocking driver like scala-redis?
Any guidance would be greatly appreciated.
Thank you very much for your time,
Nathan
(here are some of my classes, FWIW)
Base redis repository:
An implementation:
A "Repository" Actor Impl:
How I am creating the Repository Actor (one per type of Repository)