I'm new to Akka and I'm trying to run a simple remoting actor that works on localhost on a Google Cloud VM instance.
VM has both internal and external IPs. When I start an actor with IP set to external it fails to start.
But when I'm doing this
netty.tcp {
hostname = "<internal IP>"
port = 45000
Everything starts off fine.
Now obviously when trying to connect from another machine internal IP doesn't resolve, so I'm trying to find the actor using the following command:
context.actorSelection("akka.tcp://Main@<external IP>:45000/user/app")
And get the following error:
[ERROR] dropping message [class akka.actor.ActorSelectionMessage] for non-local recipient [Actor[akka.tcp://Main@external IP:45000/]] arriving at [akka.tcp://Main@external IP:45000] inbound addresses are [akka.tcp://Main@internal IP:45000]
The last part does make sense, but how do I make the whole thing work?
Found the solution.
It's based on bind-hostname
config setting available in upcoming 2.4 version:
build.sbt
resolvers += "Typesafe Snapshots" at "http://repo.akka.io/snapshots/"
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor" % "2.4-SNAPSHOT",
"com.typesafe.akka" %% "akka-remote" % "2.4-SNAPSHOT"
)
application.conf
akka {
actor {
provider = "akka.remote.RemoteActorRefProvider"
}
remote {
enabled-transports = ["akka.remote.netty.tcp"]
netty.tcp {
hostname = "external IP"
port = 45000
bind-hostname = "internal IP"
}
}
}
You can also specify bind-port
if needed.