Ali Yeşilkanat Ali Yeşilkanat - 2 months ago 32
Java Question

Akka Remote - Messages are not delivering (Java)

Trying to use Akka for parallel computing but facing a problem while communicating actors. I have two different actors (whose names are sender and receiver) which works on two different systems working on different ports on same ip address (whose names are SenderSystem and Receiver System). What I want to do is send message from sender actor to receiver actor. But on console I see a message like this

[INFO] [08/15/2015 12:36:51.645] [SenderSystem-akka.actor.default-dispatcher-4] [akka://SenderSystem/sender] Message [com.aliyesilkanat.akkadeneme.Messages$1] from Actor[akka://SenderSystem/deadLetters] to Actor[akka://SenderSystem/sender] was not delivered. [1] dead letters encountered. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.


Here is application.conf

akka {
loglevel = "INFO"
actor {
provider = "akka.remote.RemoteActorRefProvider"
}
remote {
untrusted-mode = off
enabled-transports = ["akka.remote.netty.tcp"]
netty.tcp {
hostname = "127.0.0.1"
}

}
}


sender.conf

include "application"
akka {
actor {
deployment {
/receiver {
remote = "akka://ReceiverSystem@127.0.0.1:8091"
}
}
}
remote.netty.tcp.port = 8090
}


receiver.conf

include "application"
akka {
remote.netty.tcp.port = 8091
}


Receiver.java

package com.aliyesilkanat.akkadeneme.receiver;

import com.aliyesilkanat.akkadeneme.Messages;

import akka.actor.UntypedActor;

public class Receiver extends UntypedActor {

@Override
public void onReceive(Object msg) throws Exception {
if (msg.equals(Messages.RECEIVE)) {
System.out.println("receiver receives");
}
}

}


ReceiverApplication.java

package com.aliyesilkanat.akkadeneme.receiver;

import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.Props;

import com.typesafe.config.ConfigFactory;

public class ReceiverApplication {
public static void main(String[] args) {
startRecieverSystem();
}

private static void startRecieverSystem() {
final ActorSystem system = ActorSystem.create("ReceiverSystem",
ConfigFactory.load("receiver"));
ActorRef actorOf = system.actorOf(Props.create(Receiver.class),
"receiverActor");
System.out.println("created receiver actor: " + actorOf.toString());
}
}


Sender.java

package com.aliyesilkanat.akkadeneme.sender;

import akka.actor.ActorSelection;
import akka.actor.UntypedActor;

import com.aliyesilkanat.akkadeneme.Messages;

public class Sender extends UntypedActor {

public Sender() {
}

@Override
public void onReceive(Object msg) throws Exception {
if (msg.equals(Messages.SEND)) {
System.out.println(getSender() + " sends");
ActorSelection receiverActor = getContext().actorSelection(
"akka.tcp://ReceiverSystem@127.0.0.1:8091/user/receiver"); // I am not sure about this one
receiverActor.tell(Messages.RECEIVE, getSelf());
}
}

}


SenderApplication.java

package com.aliyesilkanat.akkadeneme.sender;

import com.typesafe.config.ConfigFactory;

import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.Props;

public class SenderApplication {
private static ActorSystem system;

public static void main(String[] args) {
startSenderApp();
}

private static void startSenderApp() {
setSystem(ActorSystem.create("SenderSystem",
ConfigFactory.load("sender")));
ActorRef actorOf = getSystem().actorOf(Props.create(Sender.class),
"senderActor");
System.out.println("created sender actor: " + actorOf.toString());
}

public static ActorSystem getSystem() {
return system;
}

public static void setSystem(ActorSystem system) {
SenderApplication.system = system;
}
}


And lastly, main method

public static void main(String[] args) {
ReceiverApplication.main(null);
SenderApplication.main(null);
ActorSystem system = SenderApplication.getSystem();
ActorSelection ref = system.actorSelection("sender");
ref.tell(Messages.SEND, ActorRef.noSender());
}


entire console output

[INFO] [08/15/2015 12:48:12.220] [main] [Remoting] Starting remoting
[INFO] [08/15/2015 12:48:12.451] [main] [Remoting] Remoting started; listening on addresses :[akka.tcp://ReceiverSystem@127.0.0.1:8091]
[INFO] [08/15/2015 12:48:12.451] [main] [Remoting] Remoting now listens on addresses: [akka.tcp://ReceiverSystem@127.0.0.1:8091]
created receiver actor: Actor[akka://ReceiverSystem/user/receiverActor#2084584126]
[INFO] [08/15/2015 12:48:12.481] [main] [Remoting] Starting remoting
[INFO] [08/15/2015 12:48:12.491] [main] [Remoting] Remoting started; listening on addresses :[akka.tcp://SenderSystem@127.0.0.1:8090]
[INFO] [08/15/2015 12:48:12.491] [main] [Remoting] Remoting now listens on addresses: [akka.tcp://SenderSystem@127.0.0.1:8090]
created sender actor: Actor[akka://SenderSystem/user/senderActor#-2012370784]
[INFO] [08/15/2015 12:48:12.491] [SenderSystem-akka.actor.default-dispatcher-3] [akka://SenderSystem/sender] Message [com.aliyesilkanat.akkadeneme.Messages$1] from Actor[akka://SenderSystem/deadLetters] to Actor[akka://SenderSystem/sender] was not delivered. [1] dead letters encountered. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.

Answer

When the ActorSystem is local(same JVM) then call is akka://ActorSystem/user/ActorName. In your main method are:

ActorSelection ref = system.actorSelection("sender");

try replace the sender for akka://SenderSystem/user/senderActor