Frage

Ich versuche, ein Remote-Akka-System mit einem Play-Framework zu verbinden, und es sieht so aus, als hätte ich ein Problem mit der Konfiguration.

Ich habe eine Play-Framework-Controller-Klasse und einen Akka-Akteur, da die lokalen Objekte unten die Codes sind:

Wenn ich es ausführe, wird auf der Webseite die folgende Meldung angezeigt

[ClassNotFoundException: akka.remote.RemoteActorRefProvider]
In C:\Users\FAISAL\workspace\Rakka\app\controllers\Application.java at line 21.
17  public static Result index() throws InterruptedException { 
18    
19    System.out.println(" Local Node Called0");
20    
21    ActorSystem csystem = ActorSystem.create("Application", ConfigFactory.load().getConfig("LocalNode"));
22    ActorRef localNode = csystem.actorOf(new Props(LocalNode.class));
23
24      System.out.println(" Local Node Called1");
25      localNode.tell("Hello");

das ist der Controller:

public class Application extends Controller {



  public static Result index() throws InterruptedException { 

      System.out.println(" Local Node Called0");

      ActorSystem csystem = ActorSystem.create("Application", ConfigFactory.load().getConfig("LocalNode"));
      ActorRef localNode = csystem.actorOf(new Props(LocalNode.class));

        System.out.println(" Local Node Called1");
        localNode.tell("Hello World");
        System.out.println(" Local Node Called2");

        Thread.sleep(5000);
        csystem.shutdown();
        return ok(index.render("I am OK"));
  }    
}

Dies ist der lokale Akka-Schauspieler

public class LocalNode extends UntypedActor {

    LoggingAdapter log = Logging.getLogger(getContext().system(), this);
    Timeout timeout = new Timeout(Duration.parse("5 seconds"));

    ActorRef master;

    public void preStart()
    {
        /* Get reference to Master Node*/
         master = getContext().actorFor("akka://MasterNode@127.0.0.1:2552/user/master");
    }

    @Override
    public void onReceive(Object message) throws Exception {
        System.out.println(" Future called  ");

         Future<Object> future = Patterns.ask(master , message.toString(), timeout);

            String result = (String) Await.result(future, timeout.duration());

            log.info("Messagefrom Server", result); 
    }

}

Dies ist die lokale Play-Conf-Datei

#confige the remote connection

LocalNode {
    akka {
        actor {
            provider = "akka.remote.RemoteActorRefProvider"
        }
        remote {
            transport = "akka.remote.netty.NettyRemoteTransport"
            netty {
                hostname = "127.0.0.1"
                port = 0
            }
        }
    }
}

Der folgende Code stammt vom Remote-Akka-System.

Dies ist der Remote-Master

public class MasterNode implements Bootable
{
     final ActorSystem system;

      public MasterNode() {
        system = ActorSystem.create("MasterNode", ConfigFactory.load()
            .getConfig("master"));
        ActorRef actor = system.actorOf(new Props(MasterActor.class),"master");
        System.out.println(" Master Node is called ");
      }

      public void startup() {

      }

          public void shutdown() {
            system.shutdown();
          }
}  

Dies ist das Remote-Akka-Actor-System

public class MasterActor 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");       
    }
  }  
}

Dies ist aus der Remote-Akka-Konfiguration

master {
akka {
  actor {
    provider = "akka.remote.RemoteActorRefProvider"
  }
  remote {
    transport = "akka.remote.netty.NettyRemoteTransport"
    netty {
      hostname = "127.0.0.1"
      port = 2552
    }
 }
}}

Um das System auszuführen, starte ich zuerst das AKKA -Remote -System und starte dann das Play 2 -Framework

Nach dem Ausführen des Play-Frameworks erhalte ich die folgende Fehlermeldung

[info] play - Application started (Dev)
 Local Node Called0
[error] application -

! @6bol84j48 - Internal server error, for request [GET /] ->

play.core.ActionInvoker$$anonfun$receive$1$$anon$1: Execution exception [[ClassN
otFoundException: akka.remote.RemoteActorRefProvider]]
        at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:134) [
play_2.9.1.jar:2.0.2]
        at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:115) [
play_2.9.1.jar:2.0.2]
        at akka.actor.Actor$class.apply(Actor.scala:318) [akka-actor.jar:2.0.2]
        at play.core.ActionInvoker.apply(Invoker.scala:113) [play_2.9.1.jar:2.0.
2]
        at akka.actor.ActorCell.invoke(ActorCell.scala:626) [akka-actor.jar:2.0.
2]
        at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:197) [akka-actor.j
ar:2.0.2]
Caused by: java.lang.ClassNotFoundException: akka.remote.RemoteActorRefProvider
        at java.net.URLClassLoader$1.run(Unknown Source) ~[na:1.7.0_01]
        at java.net.URLClassLoader$1.run(Unknown Source) ~[na:1.7.0_01]
        at java.security.AccessController.doPrivileged(Native Method) ~[na:1.7.0
_01]
        at java.net.URLClassLoader.findClass(Unknown Source) ~[na:1.7.0_01]
        at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.7.0_01]
        at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.7.0_01]

Es sieht so aus, als ob ich etwas nicht richtig hinbekomme. Jeder Vorschlag oder jede Hilfe ist willkommen.

War es hilfreich?

Lösung

Möglicherweise haben Sie vergessen, die Abhängigkeit zu Akka Remote in Ihrer Play2-Anwendung hinzuzufügen.

Wenn Sie Play 2.0.3 verwenden, fügen Sie die folgende Abhängigkeit hinzu project/Build.scala Datei:

val appDependencies = Seq(
      "com.typesafe.akka" % "akka-remote" % "2.0.2"
)
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top