Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Akka.Net Remoting: ActorSelection vs. IActorRef

Tags:

c#

akka

akka.net

Using Akka.net with remoting. This article has the following to say about using ActorSelection:

The other time when I tend to use an ActorSelection is when I am initially communicating with a remote actor system.

What I don't quite understand is how to convert that initial ActorSelection into an IActorRef that I can continue to use.

like image 548
Phil Sandler Avatar asked Feb 26 '16 19:02

Phil Sandler


People also ask

What is the difference between actorref and actorselection?

ActorSelection only ever looks up existing actors when messages are delivered, i.e. does not create actors, or verify existence of actors when the selection is created. Equality of ActorRef match the intention that an ActorRef corresponds to the target actor incarnation.

What are local actor references when Remoting is enabled?

Local actor references when remoting is enabled are used by actor systems which support networking functions for those references which represent actors within the same CLR. In order to also be reachable when sent to other network nodes, these references include protocol and remote addressing information.

What is the actor path in Akka?

Each actor path has an address component, describing the protocol and location by which the corresponding actor is reachable, followed by the names of the actors in the hierarchy from the root up. Examples are: Here, akka.tcp is the default remote transport; other transports are pluggable.

How do I get an actorref for an actor?

To acquire an ActorRef that is bound to the life-cycle of a specific actor you need to send a message, such as the built-in Identify message, to the actor and use the Sender reference of a reply from the actor.


1 Answers

The simplest way here is to use actorSelection.ResolveOne(timeout) method, which will return Task<IActorRef>. Task may also end with timeout or ActorNotFoundException in case when no actor was found under provided path.

Another - more actor-idiomatic - way is to send Identify(correlationId) message to actor selection. It should respond with ActorIdentity(correlationId, actorRef) reply. Be aware that it may not respond at all, if there was no one to listen under provided actor selection.

like image 155
Bartosz Sypytkowski Avatar answered Nov 03 '22 12:11

Bartosz Sypytkowski