How to corroborate akka messages and their requests

468 views
Skip to first unread message

karthe...@gmail.com

unread,
Nov 30, 2014, 3:25:41 AM11/30/14
to akka...@googlegroups.com
Hi,

I have a code wherein I send several  messages to the akka actor. But, akka is an asynchronous message passing model. So, I couldn't match the which response from the actor is, for what request. Basically, I want to track messages and their corresponding responses. Because of the asynchronous behavior, I don't know which response belongs to what request.

Can someone please help me in tracking the corroboration between akka requests and responses?

Thank you
Karthik.  

Piyush Mishra

unread,
Nov 30, 2014, 4:36:30 AM11/30/14
to akka...@googlegroups.com

Hi Kartheek,

If it work for you, you can attach a Id with each request.

--
>>>>>>>>>> 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.

karthe...@gmail.com

unread,
Nov 30, 2014, 5:06:37 AM11/30/14
to akka...@googlegroups.com
Hi Piyush,

I am having the same idea too. But, I am dealing with Apache spark scheduler code.  I feel its gonna be really big task for me. Are there any akka API methods for achieving this?

Balázs Kossovics

unread,
Nov 30, 2014, 5:39:47 AM11/30/14
to akka...@googlegroups.com

Hi Karthik,

Did you check out the ask pattern (http://doc.akka.io/docs/akka/snapshot/scala/actors.html#Ask__Send-And-Receive-Future)? It may be the thing you need.

Soumya Simanta

unread,
Nov 30, 2014, 8:53:39 AM11/30/14
to akka...@googlegroups.com
As far as I know the following only two options: 

1. Use a requestId (or context object as in Spray) that you pass along with your messages to your actors in the chain. The advantage is that you are not setting a timeout here. But you have to deal with co-relating messages yourself. 
2. Use the ask pattern where you need to set a timeout but Akka will take care of getting the matching the request with the response. 

I was wondering if there is any other way of doing this ? 

Thanks
-Soumya

Roland Kuhn

unread,
Nov 30, 2014, 10:02:17 AM11/30/14
to akka-user
30 nov 2014 kl. 14:53 skrev Soumya Simanta <soumya....@gmail.com>:

As far as I know the following only two options: 

1. Use a requestId (or context object as in Spray) that you pass along with your messages to your actors in the chain. The advantage is that you are not setting a timeout here. But you have to deal with co-relating messages yourself. 
2. Use the ask pattern where you need to set a timeout but Akka will take care of getting the matching the request with the response. 

I was wondering if there is any other way of doing this ? 

If you consider that the real message is Envelope(payload, sender), these two options collapse into one: the only way to make sense of the response is to include identifying information in the request, which can either be placed in the payload or the sender fields. Using “ask” does the latter by creating a unique one-time recipient.

You can think of the difference also as
  1. the meta-information travels with the message (and needs to be understood by the recipient)
  2. the meta-information stays with the sender (in the form of the “ask”-ActorRef and possible Future transformation closures)

The second case is the only possibility if the recipient’s protocol does not allow disambiguation:

case Whatever(..., x) =>
  otherActor ? Request(...) collect {
    case r: Response => ResponseWithContext(r, x)
  } pipeTo self
case ResponseWithContext(r, x) =>
  // continue the process

The value `x` above is the identifying piece that allows the actor to keep different requests separate, and if the `otherActor` cannot pass back this information in its `Response` then we can remember it in the `collect` closure and piece things together afterwards.

This should motivate why you should always include client-chosen identifiers in the Actor protocols you design, because that makes this kind of dance unnecessary (i.e. `Request` should allow passing along `x`—usually called a correlation ID—and Response should just include that value as well).

Regards,

Roland


Thanks
-Soumya


On Sunday, November 30, 2014 5:39:47 AM UTC-5, Balázs Kossovics wrote:

Hi Karthik,

Did you check out the ask pattern (http://doc.akka.io/docs/akka/snapshot/scala/actors.html#Ask__Send-And-Receive-Future)? It may be the thing you need.


--
>>>>>>>>>> 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.



Dr. Roland Kuhn
Akka Tech Lead
Typesafe – Reactive apps on the JVM.
twitter: @rolandkuhn


Soumya Simanta

unread,
Nov 30, 2014, 10:34:48 AM11/30/14
to akka...@googlegroups.com
Roland, 

Thanks for explaining this very nicely. This is consistent with my understanding. 

I try to avoid using the ask pattern (if I can) because of the timeout issue. 

So basically if you have complete control over all your messages, it better to explicitly pass a unique message identifier and use that to track the request-response flow. 
Do you agree with this recommendation? 

Thanks again ! 
-Soumya

Roland Kuhn

unread,
Nov 30, 2014, 11:19:42 AM11/30/14
to akka-user
30 nov 2014 kl. 16:34 skrev Soumya Simanta <soumya....@gmail.com>:

Roland, 

Thanks for explaining this very nicely. This is consistent with my understanding. 

I try to avoid using the ask pattern (if I can) because of the timeout issue. 

So basically if you have complete control over all your messages, it better to explicitly pass a unique message identifier and use that to track the request-response flow. 
Do you agree with this recommendation? 

Yes.

Regards,

Roland

何品

unread,
Nov 30, 2014, 11:37:04 AM11/30/14
to akka...@googlegroups.com
try this way

type RequestSeqNr = Long
type ResponsePromise = Promise[?]
tracking :Map[RequestSeqNr,ResponsePromise]

when you passing the request to the other actor via Request(RquestSeqNr,msg)
after then finished ,response you the RequestHandled(RquestSeqNr,usefulData)

then you could extract the RquestSeqNr and finish the ResponsePromise

so ,I think if you are using play with akka ,you may occur this issue.:P
















在 2014年11月30日星期日UTC+8下午4时25分41秒,karthe...@gmail.com写道:
Reply all
Reply to author
Forward
0 new messages