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.
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With