I'm not sure if you can "forward" instead of "route" to a router, if not 
you could probably set the router sender to sender() and just reply to the 
sender from the processing actor,
that way you won't need to correlate, it should be do-able using existing 
sender() reply mechanism.

The trick would be to:

router.route(message,sender());

HTH,

Guido.

On Tuesday, April 25, 2017 at 9:33:40 AM UTC+1, Vishwa Bhat wrote:
>
> Nice, That's one solution but what if I have to do some processing on 
> 'MainActor' when I get response from child and then I have to send to 
> 'MyApp'?
>
> Regards,
> Vishwa
>
> On Tuesday, April 25, 2017 at 1:38:09 PM UTC+5:30, Arnout Engelen wrote:
>>
>> Hi Vishwa,
>>
>> You correctly noticed that, when handling the Integer message that was 
>> sent to the 'MainActor' by your child actor, 'sender()' will refer to that 
>> child actor.
>>
>> If you want the response to go to the 'original' sender ('MyApp'), one 
>> solution might be to use 'sender()' as the second parameter to 'route': 
>> this will tell the child to send its response directly to 'MyApp', 
>> effectively 'forwarding' the message.
>>
>>
>> Kind regards,
>>
>> Arnout
>>
>> On Tue, Apr 25, 2017 at 8:57 AM, Vishwa Bhat <[email protected]> 
>> wrote:
>>
>>> I have the following issue in Akka-Java.
>>>
>>> I have one Parent Actor `MainActor.class` and this parent has 5 child 
>>> routes. Following is the hierarchy:
>>>
>>> *My App => Main Actor => [Child Route-1,Child-Route-2,..]*
>>>
>>> Simple Use case is String input is parsed to Integer as output: 
>>>
>>> *MyApp ===ask[string input]===> Main Actor ==route==> Child(parses to 
>>> Integer) === integer result===> Main Actor ===result==> MyApp*
>>>
>>> Here is the Main Actor snippet:
>>>
>>>
>>>  class MainActor extends UntypedActor{
>>>     
>>>        Router router;
>>>        {
>>>          // ...routes are configured here
>>>        }
>>>     
>>>        public void onReceive(Object message){
>>>          if(message instanceof String){
>>>              router.route(message,self()); // route it to child
>>>          }else if(message instanceof Integer){
>>>             // received from child, 'tell' this result to actual 
>>> sender/parent i.e, MyApp
>>>             sender().tell(message,self()); 
>>>          }else unhandled(message);
>>>         }
>>>  }
>>>
>>> And Child Actor does nothing but String parsing to Integer and takes the 
>>> result and sends it back to it's sender by 
>>> `sender().tell(result,getContext().parent())`
>>>
>>> *Issue*
>>>
>>> MainActor is sending the Parsed integer result sent by child back to 
>>> child itself instead of `MyApp`. I also tried replacing `*sender()*` to 
>>> `*getContext().parent()*` in `MainActor` but still it did not work.
>>>
>>> -- 
>>> >>>>>>>>>> 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 [email protected].
>>> To post to this group, send email to [email protected].
>>> Visit this group at https://groups.google.com/group/akka-user.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> -- 
>> Arnout Engelen
>> *Senior Software Engineer*
>> E: [email protected]
>> T: https://twitter.com/raboofje
>>
>>
>>

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

Reply via email to