I am running sample example for akka remoting (2.0.2) in java (1.6) and not getting results from remote. It seems that my local node is not able to connect to remote note.
LocalNodeApplication code is on local system and RemoteNodeApplication code is on remote system.
Please refer code :
Local Node –
public class LocalNodeApplication extends Controller {
public static Result process(String msg) throws Exception {
ActorSystem _system = ActorSystem.create("LocalNodeApp", ConfigFactory.load().getConfig("LocalSys"));
ActorRef localActor = _system.actorOf(new Props(LocalActor.class));
localActor.tell("Hello");
Thread.sleep(5000);
_system.shutdown();
return ok("success");
}
}
LocalActor code :
public class LocalActor extends UntypedActor {
LoggingAdapter log = Logging.getLogger(getContext().system(), this);
Timeout timeout = new Timeout(Duration.parse("5 seconds"));
ActorRef remoteActor;
@Override
public void preStart() {
//Get a reference to the remote actor
remoteActor = getContext().actorFor("akka://RemoteNodeApp@192.168.0.85:9002/user/remoteActor");
}
@Override
public void onReceive(Object message) throws Exception {
Future<Object> future = Patterns.ask(remoteActor, message.toString(), timeout);
String result = (String) Await.result(future, timeout.duration());
log.info("Message received from Server -> {}", result);
/*remoteActor.tell(message.toString());*/
}
}
LocalSys config :
LocalSys {
akka {
actor {
provider = "akka.remote.RemoteActorRefProvider"
deployment {
/remoteActor {
remote = "akka://RemoteNodeApp@192.168.0.85:9002"
}
}
}
}
}
Remote Node code –
RemoteNodeApplication
public class RemoteNodeApplication implements Bootable {
final ActorSystem system = ActorSystem.create("RemoteNodeApp", ConfigFactory.load().getConfig("RemoteSys"));
public void shutdown() {
system.shutdown();
}
public void startup() {
system.actorOf(new Props(RemoteActor.class), "remoteActor");
}
}
RemoteActor :
public class RemoteActor extends UntypedActor {
@Override
public void onReceive(Object message) throws Exception {
if (message instanceof String) {
// Get reference to the message sender and reply back
getSender().tell(message + " got something");
}
}
}
RemoteSys config –
RemoteSys {
akka {
actor {
provider = "akka.remote.RemoteActorRefProvider"
}
remote {
untrusted-mode = on
transport = "akka.remote.netty.NettyRemoteTransport"
netty {
hostname = "192.168.0.85"
port = 9002
}
}
}
}
I am starting play “run 9000” on local node and on remote starting play “run 9002” .
I am getting below mentioned exception :
[INFO] [09/17/2012 17:42:52.206] [play-akka.actor.actions-dispatcher-1] [ActorSystem(LocalNodeApp)] REMOTE: RemoteServerStarted@akka://LocalNodeApp@127.0.0.1:2552
[INFO] [09/17/2012 17:42:52.406] [LocalNodeApp-akka.actor.default-dispatcher-4] [ActorSystem(LocalNodeApp)] REMOTE: RemoteClientStarted@akka://RemoteNodeApp@192.168.0.85:9002
[INFO] [09/17/2012 17:42:52.438] [LocalNodeApp-akka.actor.default-dispatcher-1] [ActorSystem(LocalNodeApp)] REMOTE: RemoteClientShutdown@akka://RemoteNodeApp@192.168.0.85:9002
[ERROR] [09/17/2012 17:42:57.281] [LocalNodeApp-akka.actor.default-dispatcher-4] [akka://LocalNodeApp/user/$a] Timed out
akka.pattern.AskTimeoutException: Timed out
at akka.dispatch.DefaultPromise.result(Future.scala:875)
at akka.dispatch.Await$.result(Future.scala:74)
at akka.dispatch.Await.result(Future.scala)
at com.localNodeApp.LocalActor.onReceive(LocalActor.java:30)
at akka.actor.UntypedActor$$anonfun$receive$1.apply(UntypedActor.scala:154)
at akka.actor.UntypedActor$$anonfun$receive$1.apply(UntypedActor.scala:153)
at akka.actor.Actor$class.apply(Actor.scala:318)
at akka.actor.UntypedActor.apply(UntypedActor.scala:93)
at akka.actor.ActorCell.invoke(ActorCell.scala:626)
at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:197)
at akka.dispatch.Mailbox.run(Mailbox.scala:179)
at akka.dispatch.ForkJoinExecutorConfigurator$MailboxExecutionTask.exec(AbstractDispatcher.scala:516)
at akka.jsr166y.ForkJoinTask.doExec(ForkJoinTask.java:259)
at akka.jsr166y.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:975)
at akka.jsr166y.ForkJoinPool.runWorker(ForkJoinPool.java:1479)
at akka.jsr166y.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:104)
Caused by: akka.pattern.AskTimeoutException: Timed out
at akka.pattern.PromiseActorRef$$anonfun$1.apply$mcV$sp(AskSupport.scala:274)
at akka.actor.DefaultScheduler$$anon$6$$anon$7.run(Scheduler.scala:183)
at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:94)
at akka.jsr166y.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1381)
... 4 more
[INFO] [09/17/2012 17:42:57.318] [LocalNodeApp-akka.actor.default-dispatcher-4] [ActorSystem(LocalNodeApp)] REMOTE: RemoteServerShutdown@akka://LocalNodeApp@127.0.0.1:2552
When I am running the same example on local system for both local node and remote node (for this changed IP address to local system) getting below mentioned lines on console :
[INFO] [09/17/2012 17:42:52.206] [play-akka.actor.actions-dispatcher-1] [ActorSystem(LocalNodeApp)] REMOTE: RemoteServerStarted@akka://LocalNodeApp@127.0.0.1:2552
[INFO] [09/17/2012 17:42:52.406] [LocalNodeApp-akka.actor.default-dispatcher-4] [ActorSystem(LocalNodeApp)] REMOTE: RemoteClientStarted@akka://RemoteNodeApp@192.168.0.85:9002
[INFO] [09/17/2012 17:42:52.438] [LocalNodeApp-akka.actor.default-dispatcher-1] [ActorSystem(LocalNodeApp)] REMOTE: RemoteClientShutdown@akka://RemoteNodeApp@192.168.0.85:9002
[INFO] [09/17/2012 17:42:57.318] [LocalNodeApp-akka.actor.default-dispatcher-4] [ActorSystem(LocalNodeApp)] REMOTE: RemoteServerShutdown@akka://LocalNodeApp@127.0.0.1:2552
Please guide me on this.
Am I following right steps for akka remoting ?
the remoteapplication need to be deployed as jar in the akka
microkernal. Once the remote application starts, you can run the local
application to connect to the remote app. answered by write2munish