Beginner question: ReactiveMongo with Akka

30 views
Skip to first unread message

mniel...@gmail.com

unread,
Sep 17, 2016, 11:18:33 AM9/17/16
to ReactiveMongo - http://reactivemongo.org
Hi,

The documentation for ReactiveMongo says:

In general, a MongoDriver or a MongoConnection should not be instantiated more than once.

I get that.  

So what's the correct way to give each of what may be many actors, not necessarily sharing the same parent, access to the connection pool?


Cédric Chantepie

unread,
Sep 17, 2016, 2:10:08 PM9/17/16
to ReactiveMongo - http://reactivemongo.org
Need to be more specific

Mike Nielsen

unread,
Sep 17, 2016, 3:07:50 PM9/17/16
to reacti...@googlegroups.com
Sorry, my question may have been a little terse.  I hope my elaboration following is more suitable.

Assume I have a bunch of actors in the same actorSystem that are routees for some function that requires database access: say for example that a client sends the router a request that can be decomposed into sub-requests, each with a key.  The routees read their assigned key from the database, perform some computation and write the result back.  Each of them thus needs access to the collection in question, which can be derived from a connection which in turn is derived from the driver.

The way I read the documentation, I should instantiate the driver only once; same with the connection.  Consequently, if my understanding is correct, the routees must be provided with the connection to use.

Is the best way to make sure that they have the connection via dependency injection from a singleton object, or is there some other way?  Or do I misunderstand the documentation?



On Sat, Sep 17, 2016 at 2:10 PM, Cédric Chantepie <chantep...@gmail.com> wrote:
Need to be more specific

--
You received this message because you are subscribed to a topic in the Google Groups "ReactiveMongo - http://reactivemongo.org" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/reactivemongo/jqeBPbCX_tM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to reactivemongo+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Cédric Chantepie

unread,
Sep 17, 2016, 7:49:43 PM9/17/16
to ReactiveMongo - http://reactivemongo.org
To work with the same pool, the actors must be created with the same MongoConnection instance, which must be passed to the appropriate constructor (see Akka doc).
Reply all
Reply to author
Forward
0 new messages