public class AkkaPing {
@SuppressWarnings("unused")
public static void main(String[] args) {
final ActorSystem pingSystem = ActorSystem.create("PingApplication",
ConfigFactory.load().getConfig("PingConfig"));
final ActorSelection pongSelection = pingSystem
.actorSelection("akka.tcp://PongApp...@127.0.0.1:5152/user/PongActor");
System.out.println("*************Sending the first Ping***********");
pongSelection.tell(new Message("sunny"), ActorRef.noSender());
final class PingActor extends UntypedAbstractActor {
public PingActor() {
super();
}
@Override
public void onReceive(Object message) {
if (message instanceof Message) {
Message recMsg = (Message) message;
System.out.println("Received Message: " + recMsg.toString());
pongSelection.tell(recMsg, getSelf());
} else {
System.out.println("UnHandled Message Received");
unhandled(message);
}
}
}
}
}
PingConfig {
akka {
actor {
serializers {
java = "akka.serialization.JavaSerializer"
proto = "akka.remote.serialization.ProtobufSerializer"
myown = "docs.serialization.MyOwnSerializer"
}
serialization-bindings {
"java.lang.String" = java
"docs.serialization.Customer" = java
"com.google.protobuf.Message" = proto
"docs.serialization.MyOwnSerializable" = myown
"java.lang.Boolean" = myown
}
provider = remote
}
remote {
akka.remote.trusted-selection-paths = ["/user/PongActor"]
enabled-transports = ["akka.remote.netty.tcp"]
netty.tcp {
hostname = "127.0.0.1"
port=5153
}
}
}
}
public class AkkaPong {
public static void main(String[] args) {
final ActorSystem pongSystem = ActorSystem.create("PongApplication",
ConfigFactory.load().getConfig("PongConfig"));
final ActorSelection pingSelection = pongSystem
.actorSelection("akka.tcp://PingApp...@127.0.0.1:5153/user/PingActor");
final class PongActor extends UntypedAbstractActor {
public PongActor() {
super();
}
@Override
public void onReceive(Object message) {
if (message instanceof Message) {
Message recMsg = (Message) message;
System.out.println("Received Message: " + recMsg.toString());
pingSelection.tell(recMsg, getSelf());
} else {
System.out.println("UnHandled Message Received");
unhandled(message);
}
}
}
}
}
application.conf for AkkaPong project
PongConfig {akka { actor { provider = remote } remote { akka.remote.trusted-selection-paths = ["/user/PingActor"] enabled-transports = ["akka.remote.netty.tcp"] netty.tcp { hostname = "127.0.0.1" port=5152 } }}}
Hello Guys..I am new to akka. Was trying out a remote ping pong application using java. I cannot make it to work. Can anyone tell me what am doing wrong.
I have created 2 projects AkkaPing and AkkaPing, Below is the code snippets.
public class AkkaPing {
@SuppressWarnings("unused")
public static void main(String[] args) {
final ActorSystem pingSystem = ActorSystem.create("PingApplication",
ConfigFactory.load().getConfig("PingConfig"));
final ActorSelection pongSelection = pingSystem
.actorSelection("akka.tcp://PongAppl...@127.0.0.1:5152/user/PongActor");
application.conf for AkkaPing project.
.actorSelection("akka.tcp://PingAppl...@127.0.0.1:5153/user/PingActor");