Asynchronous processing in onReceive of Actor

78 views
Skip to first unread message

Kalpak Gadre

unread,
Aug 27, 2016, 2:01:45 PM8/27/16
to Akka User List
Hi,

I am using Play Framework 2.5.x Java. I have a use case where I need to create a process that,

1. Polls Amazon SQS for message(s)
2. For each message, download some file from S3.
3. Update Mongo with new data as per message.
4. Delete the message from SQS.

I have already created non-blocking APIs for all the steps. The APIs produce a CompletionStage object. I am evaluating options modeling this processing using Akka Actors.

I am thinking about following options,

1. Scheduler:
 - A scheduler will trigger an actor to poll for messages.
 - I will use the CompletionStage returned by the receive message API to weave together further steps asynchronously.

2. Scheduler + Message Processing Actor
 - A scheduler will trigger an actor to poll for messages.
 - Each message will be pushed (tell) to an actor which processes the messages.
 - Message processing actor will use chaining of CompletionStage to process the message asynchronously. 

3. Scheduler + Message Processing Actor per message
 - A scheduler will trigger an actor to poll for messages.
 - Each message will be pushed (tell) to it's dedicated instance of an actor which processes the messages.
 - Message processing actor will use chaining of CompletionStage to process the message asynchronously. 

I have following questions,

1. As per scheduler's documentation, the scheduler will fire as per fixed schedule. It is possible that there are 2 polls of SQS happening at the same time in case the amount of time required by a single poll exceeds scheduler's interval. Ideally I need a construct which triggers another poll only after the first one is complete (closely related to a loop) What is the best way to achieve this? I have also thought about an actor messaging itself after it has performed 1 poll.

2. It is mentioned in the documentation that an actor should not process next message until the current message is processed. If I use chaining of CompletionStage, I will be returning from the onReceive() method of actor prematurely. Is this acceptable? If not, what is an alternative? How do I chain the CompletionStage to weave further operations on the result? I did read about pipe. I can pipe the CompletionStage to the same / another actor to perform the next step. Even if I use pipe, I am still allowing another message into onReceive before the previous one is actually completed processing?

Any suggestions how this process should be modeled for Akka?

Thanks,

Kalpak

Viktor Klang

unread,
Aug 27, 2016, 3:16:14 PM8/27/16
to Akka User List
Akka Streams?

--
>>>>>>>>>> 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+unsubscribe@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.



--
Cheers,

Kalpak Gadre

unread,
Sep 6, 2016, 1:07:52 AM9/6/16
to Akka User List
Thanks!

Yes, Akka streams is possibly what I was looking for. I was under impression that I do not need to create a thread and there should be a way to manage the poller thread through Akka.

My second questions which I am still unable to get any comprehensive answers online is if it is Ok to do chaining of completion stages and return a composed completion stage, that is prematurely return from the onReceive of actor and potentially have multiple messages being processed simultaneously per actor?

Thanks,

Kalpak
Akka Streams?

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 https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.



--
Cheers,

Viktor Klang

unread,
Sep 6, 2016, 2:31:54 AM9/6/16
to Akka User List

For the second question, have a look at "stash" in the documentation. (I am on my phone so access to docs is limited atm)

--
Cheers,


To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages