Akka基于Runnable Jar

时间:2017-09-12 08:52:25

标签: java eclipse akka

我正在尝试从命令行运行一个可运行的jar,该命令行中嵌入了几个akka进程。 虽然我不是应用程序的原始作者,但我知道代码确实在日食中运行得非常愉快。 然而,当我尝试导出然后作为可运行的Jar运行时,它会在一段时间后崩溃,那就是它开始启动akka进程时。 我正在使用Java 8

运行它
java -jar something.jar {options}

错误:

   at akka.actor.ActorInitializationException$.apply(Actor.scala:174)
    at akka.actor.ActorCell.create(ActorCell.scala:607)
    at akka.actor.ActorCell.invokeAll$1(ActorCell.scala:461)
    at akka.actor.ActorCell.systemInvoke(ActorCell.scala:483)
    at akka.dispatch.Mailbox.processAllSystemMessages(Mailbox.scala:282)
    at akka.dispatch.Mailbox.run(Mailbox.scala:223)
    at akka.dispatch.Mailbox.exec(Mailbox.scala:234)
    at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
    at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
    at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
    at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
    Caused by: akka.ConfigurationException: ActorSystem [akka://ClusterSystem] needs to have a 'ClusterActorRefProvider' enabled in the configuration, currently uses [akka.actor.LocalActorRefProvider]
    at akka.cluster.Cluster.<init>(Cluster.scala:71)
    at akka.cluster.Cluster$.createExtension(Cluster.scala:34)
    at akka.cluster.Cluster$.createExtension(Cluster.scala:29)
    at akka.actor.ActorSystemImpl.registerExtension(ActorSystem.scala:737)
    at akka.actor.ExtensionId$class.apply(Extension.scala:79)
    at akka.cluster.Cluster$.apply(Cluster.scala:29)
    at akka.actor.ExtensionId$class.get(Extension.scala:91)
    at akka.cluster.Cluster$.get(Cluster.scala:30)
    at akka.cluster.Cluster.get(Cluster.scala)
    at com.dynniq.its.csm.core.akka.Actor.preStart(Actor.java:93)
    at akka.actor.Actor$class.aroundPreStart(Actor.scala:489)
    at akka.actor.UntypedActor.aroundPreStart(UntypedActor.scala:95)
    at akka.actor.ActorCell.create(ActorCell.scala:590)

    @Override
    public void preStart() {
    **cluster = Cluster.get(getContext().system());**
    cluster.subscribe(getSelf(), MemberUp.class);
    preStartExtra();
    }

但正如我所说它似乎在日食环境中起作用。 我做错了什么?

提前致谢。

1 个答案:

答案 0 :(得分:0)

答案在错误消息的中间:

Caused by: akka.ConfigurationException: ActorSystem [akka://ClusterSystem] needs to have a 'ClusterActorRefProvider' enabled in the configuration, currently uses [akka.actor.LocalActorRefProvider]

简单的群集配置如下所示,请注意akka.actor.provider设置:

http://doc.akka.io/docs/akka/2.1.2/cluster/cluster-usage-scala.html

akka {
  actor {
    provider = "akka.cluster.ClusterActorRefProvider"
  }
  remote {
    transport = "akka.remote.netty.NettyRemoteTransport"
    log-remote-lifecycle-events = off
    netty {
      hostname = "127.0.0.1"
      port = 0
    }
  }

  cluster {
    seed-nodes = [
      "akka://ClusterSystem@127.0.0.1:2551", 
      "akka://ClusterSystem@127.0.0.1:2552"]

    auto-down = on
  }
}

在较新版本的Akka中,配置略有不同,请参阅http://doc.akka.io/docs/akka/current/scala/cluster-usage.html

中的详细信息
  actor {
    provider = "cluster"
  }

因此,您的应用由于某种原因无法从资源中读取application.conf,或者配置文件未作为参数正确传递给java -jar