Reputation: 2876
I'm a newbie Akka developer and I've just started with remoting. I'm always seeing this type of configuration:
akka {
actor {
provider = "akka.remote.RemoteActorRefProvider"
deployment {
"/mainRepository/*" {
remote = "akka.tcp://[email protected]:2553"
}
}
}
remote {
netty.tcp {
hostname = "127.0.0.1"
}
}
remote.netty.tcp.port = 2553
}
where actors are named, for example "mainRepository" but what if I want to create unnamed remote actors? What should I specify in the configuration? Or can I accomplish that by just not setting the name parameter in the ActorSystem when requesting a new actor?
Also, what does the "*" character mean? Or where can I learn more about the remote configuration? (aside from akka.io)
Upvotes: 0
Views: 156
Reputation: 35443
What this config is saying is that if any actor instances are created under the path /user/mainRepository/*
(that is, any children of the actor instance bound to the name /user/mainRepository
) should not be deployed to the local ActorSystem
but should instead use the remote daemon of the remote system [email protected]:2553
to deploy this actor in that remote system. So if I do something like:
context.actorOf(Props[MyActor], "foo")
Where context
is the ActorContext
for my mainRepository
actor instance, then that child will be deployed remotely.
The *
is a wildcard that lets you be more general with what actors would be deployed remotely. If the config was this:
"/mainRepository/foo" {
remote = "akka.tcp://[email protected]:2553"
}
Then only the child bound to the name foo
would be remotely deployed. Any other children to my mainRepository
actor would be deployed into the local ActorSystem
.
So using this approach, with the wildcard, you can indeed create unnamed children and have them deployed remotely, as long as their parent is properly named and that name is configured (as in this example) to deploy it's children remotely.
You can also programmatically deploy actor instances remotely if using this config driven approach does not appeal to you. That would look something like this:
import akka.actor.{ Props, Deploy, Address, AddressFromURIString }
import akka.remote.RemoteScope
val address = Address("akka.tcp", "RemoteSystem", "1.2.3.4", 1234)
val ref = system.actorOf(Props[MyActor].
withDeploy(Deploy(scope = RemoteScope(address))))
In the above code, an instance of MyActor will be deployed on the remote node [email protected]:1234
.
For more info, you can consult the Remoting docs here.
Upvotes: 1