using actors with db queries

102 views
Skip to first unread message

AL

unread,
Apr 5, 2015, 10:10:31 AM4/5/15
to akka...@googlegroups.com
Hi 
Just want to consult if this make sense .
I have an actor that uses as a service to fetch data from the db .
for accessing the DB we have a Java Spring project with hibernate and Jpa Repository 
what is the best participate for testings : 
the actor should receive as a parameter the repository something like this :
class FooService(invoicesRepo:InvoicesRepository,...more repositories goes here ... ) extends Actor ....
and while testing to send mock[InvoicesRepository]

two questions : 
is that make sense to use an actor to fetch/update data from the db (tried to find examples at typesafe activator templates but couldn't really find actors )?
if the answer is yes - is it a good practice to send the repository to actor ? or is it better use dependency injection 

any examples will be appreciated 

Thanks



Martynas Mickevičius

unread,
Apr 17, 2015, 9:14:06 AM4/17/15
to akka...@googlegroups.com
Hi,

On Sun, Apr 5, 2015 at 5:10 PM, AL <123...@gmail.com> wrote:
Hi 
Just want to consult if this make sense .
I have an actor that uses as a service to fetch data from the db .
for accessing the DB we have a Java Spring project with hibernate and Jpa Repository 
what is the best participate for testings : 
the actor should receive as a parameter the repository something like this :
class FooService(invoicesRepo:InvoicesRepository,...more repositories goes here ... ) extends Actor ....
and while testing to send mock[InvoicesRepository]

two questions : 
is that make sense to use an actor to fetch/update data from the db (tried to find examples at typesafe activator templates but couldn't really find actors )?

Do you have a particular reason you started to think about encapsulating DB access to an actor? Actors are about distribution and about encapsulating state that can be safely accessed concurrently. There are situations where one could choose to put all the code that accesses the DB to an actor so access to DB is only from a one thread at a time, but that is a very specific requirement.
 
if the answer is yes - is it a good practice to send the repository to actor ? or is it better use dependency injection 

When sending dependencies in a message you need to make sure that your actor does not start handling business messages until dependencies are sent in. Also you will have to take care of actor restarts. Therefore passing in dependencies as constructor arguments require less management.
 

any examples will be appreciated 

Thanks



--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.



--
Martynas Mickevičius
TypesafeReactive Apps on the JVM

Avi Levi

unread,
Apr 17, 2015, 11:08:56 AM4/17/15
to akka...@googlegroups.com
Thank you very much for your replay .
actually  I am using a sort of scatter gather pattern to fetch data . each actor should fetch part of data according to param (e.d customer ID) . and an actor that aggregates the results applying some business logic and stores the result in the db .  

so what is the best practice to achieve that  ? should I send the repository to each actor constructor  ? or using cake pattern or other abstraction   ?

Best
AL
 



You received this message because you are subscribed to a topic in the Google Groups "Akka User List" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/akka-user/e75kStFFdVQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to akka-user+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages