scala - How do you manage database connections using Akka actors? -


i've been studying akka time , building app utilizes actor model , requires maintain connection database, have dilemma: put connection , how can manage it?

this reasoning far:

  • the connection should initialized once.
  • since connection represents state, should reside inside actor. let's call actor databaseconnection (just creative).
  • since don't want share actor's state, querying should happen inside actor.
  • the database driver using reactive-mongo each query returns future can piped sender.

even though querying done through futures, can't thinking model cannot scale. 1 thread managing database access messages? sounds unreasonable utilizing futures. have thought of making child workers manage database querying have share connection children. last idea because if databaseconnection actor dies, children die in theory. don't know if there better way solve problem without sharing state. there?

based on example code reactive mongo doesn't actor encapsulation necessary. examining code sample:

val collection = db[bsoncollection]("articles")  val query = bsondocument()  val cursor = collection.find(query).cursor[bsondocument]  val futurelist = cursor.tolist 

the collection object acts entity encapsulates state of "connection" , responds "queries" future results. exact definition of actor thinking of creating.

wrapping above code inside of actor body doesn't seem buy much...


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -