具有多个种子节点的akka​​群集不形成群集

时间:2018-01-07 00:15:33

标签: akka-cluster

我试图按照akka in action一书的说明实现3种子群集示例应用程序。

该示例是关于创建3个看到的节点并将节点作为集群加入。

这是我的seed.conf文件。

启动ActorSystem的我的应用程序是here

作者提到使用以下命令启动3个终端

1. sbt -DPORT=2551 -DHOST=127.0.0.1

2. sbt -DPORT=2552 -DHOST=127.0.0.1

3. sbt -DPORT=2553 -DHOST=127.0.0.1

并在第14章项目中运行app.Main。

当运行第一个上述任何命令时,第一个actor系统成功启动。

当我开始下一个剩下的两个命令中的任何一个时,我总是得到以下错误。但是根据作者的说法,这3个应该形成集群。

$ sbt -DPORT=2552 -DHOST=127.0.0.1
[info] Loading settings from idea.sbt,plugins.sbt ...
[info] Loading global plugins from /Users/rajkumar.natarajan/.sbt/1.0/plugins
[info] Loading project definition from /Users/rajkumar.natarajan/Documents/Coding/akka_in_action/project
[info] Loading settings from build.sbt ...
[info] Set current project to akka in action (in build file:/Users/rajkumar.natarajan/Documents/Coding/akka_in_action/)
sbt:akka in action> project chapter14
[info] Set current project to chapter14 (in build file:/Users/rajkumar.natarajan/Documents/Coding/akka_in_action/)
sbt:chapter14> run
[info] Running (fork) app.Main
[info] [INFO] [01/06/2018 18:47:39.196] [main] [akka.remote.Remoting] Starting remoting
[info] [ERROR] [01/06/2018 18:47:39.332] [words-akka.remote.default-remote-dispatcher-13] [NettyTransport(akka://words)] failed to bind to /127.0.0.1:2552, shutting down Netty transport
[error] Exception in thread "main" org.jboss.netty.channel.ChannelException: Failed to bind to: /127.0.0.1:2552
[error]     at org.jboss.netty.bootstrap.ServerBootstrap.bind(ServerBootstrap.java:272)
[error]     at akka.remote.transport.netty.NettyTransport.$anonfun$listen$1(NettyTransport.scala:417)
[error]     at scala.util.Success.$anonfun$map$1(Try.scala:251)
[error]     at scala.util.Success.map(Try.scala:209)
[error]     at scala.concurrent.Future.$anonfun$map$1(Future.scala:289)
[error]     at scala.concurrent.impl.Promise.liftedTree1$1(Promise.scala:29)
[error]     at scala.concurrent.impl.Promise.$anonfun$transform$1(Promise.scala:29)
[error]     at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:60)
[error]     at akka.dispatch.BatchingExecutor$AbstractBatch.processBatch(BatchingExecutor.scala:55)
[error]     at akka.dispatch.BatchingExecutor$BlockableBatch.$anonfun$run$1(BatchingExecutor.scala:91)
[error]     at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
[error]     at scala.concurrent.BlockContext$.withBlockContext(BlockContext.scala:81)
[error]     at akka.dispatch.BatchingExecutor$BlockableBatch.run(BatchingExecutor.scala:91)
[error]     at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:40)
[error]     at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(ForkJoinExecutorConfigurator.scala:43)
[error]     at akka.dispatch.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
[error]     at akka.dispatch.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
[error]     at akka.dispatch.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
[error]     at akka.dispatch.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
[error] Caused by: java.net.BindException: Address already in use
[error]     at sun.nio.ch.Net.bind0(Native Method)
[error]     at sun.nio.ch.Net.bind(Net.java:433)
[error]     at sun.nio.ch.Net.bind(Net.java:425)
[error]     at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
[error]     at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
[error]     at org.jboss.netty.channel.socket.nio.NioServerBoss$RegisterTask.run(NioServerBoss.java:193)
[error]     at org.jboss.netty.channel.socket.nio.AbstractNioSelector.processTaskQueue(AbstractNioSelector.java:391)
 [error]    at org.jboss.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:315)
 [error]    at org.jboss.netty.channel.socket.nio.NioServerBoss.run(NioServerBoss.java:42)
 [error]    at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)
 [error]    at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)
 [error]    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
 [error]    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
 [error]    at java.lang.Thread.run(Thread.java:748)
 [info] [INFO] [01/06/2018 18:47:39.374] [words-akka.remote.default-remote-dispatcher-13] [akka://words/system/remoting-terminator] Shutting down remote daemon.
 [info] [INFO] [01/06/2018 18:47:39.376] [words-akka.remote.default-remote-dispatcher-13] [akka://words/system/remoting-terminator] Remote daemon shut down; proceeding with flushing remote transports.
 [info] [INFO] [01/06/2018 18:47:39.378] [words-akka.remote.default-remote-dispatcher-5] [akka://words/system/remoting-terminator] Remoting shut down.
 [info] [ERROR] [01/06/2018 18:47:39.378] [words-akka.remote.default-remote-dispatcher-4] [akka.remote.Remoting] Remoting system has been terminated abrubtly. Attempting to shut down transports
 [error] java.lang.RuntimeException: Nonzero exit code returned from runner: 1
 [error]    at sbt.ForkRun.processExitCode$1(Run.scala:29)
 [error]    at sbt.ForkRun.run(Run.scala:38)
 [error]    at sbt.Defaults$.$anonfun$bgRunTask$5(Defaults.scala:1155)
 [error]    at sbt.Defaults$.$anonfun$bgRunTask$5$adapted(Defaults.scala:1150)
 [error]    at sbt.internal.BackgroundThreadPool.$anonfun$run$1(DefaultBackgroundJobService.scala:359)
 [error]    at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
 [error]    at scala.util.Try$.apply(Try.scala:209)
 [error]    at sbt.internal.BackgroundThreadPool$BackgroundRunnable.run(DefaultBackgroundJobService.scala:282)
 [error]    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
 [error]    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
 [error]    at java.lang.Thread.run(Thread.java:748)
 [error] (chapter14/compile:run) Nonzero exit code returned from runner: 1
 [error] Total time: 2 s, completed Jan 6, 2018 6:47:39 PM

已经启动的(启动的第一个节点)节点给出了以下警告消息 -

[info] [WARN] [01/06/2018 19:12:03.471] [New I/O boss #3] [NettyTransport(akka://words)] Remote connection to [null] failed with java.net.ConnectException: Connection refused: /127.0.0.1:2551
[info] [WARN] [01/06/2018 19:12:03.472] [words-akka.remote.default-remote-dispatcher-123 [akka.tcp://words@127.0.0.1:2552/system/endpointManager/reliableEndpointWriter-akka.tcp%3A%2F%2Fwords%40127.0.0.1%3A2551-0] Association with remote system [akka.tcp://words@127.0.0.1:2551] has failed, address is now gated for [5000] ms. Reason: [Association failed with [akka.tcp://words@127.0.0.1:2551]] Caused by: [Connection refused: /127.0.0.1:2551]
[info] [WARN] [01/06/2018 19:12:03.472] [New I/O boss #3] [NettyTransport(akka://words)] Remote connection to [null] failed with java.net.ConnectException: Connection refused: /127.0.0.1:2553
[info] [WARN] [01/06/2018 19:12:03.472] [words-akka.remote.default-remote-dispatcher-119][akka.tcp://words@127.0.0.1:2552/system/endpointManager/reliableEndpointWriter-akka.tcp%3A%2F%2Fwords%40127.0.0.1%3A2553-1] Association with remote system [akka.tcp://words@127.0.0.1:2553] has failed, address is now gated for [5000] ms. Reason: [Association failed with [akka.tcp://words@127.0.0.1:2553]] Caused by: [Connection refused: /127.0.0.1:2553]

1 个答案:

答案 0 :(得分:0)

正如我在日志中看到的那样,应用程序无法找到免费端口。

"Caused by: java.net.BindException: Address already in use"

可能你试图在同一个端口上多次绑定netty端口。

作为解决方案,您可以尝试使用以下命令运行应用程序,而不是" sbt -DPORT = 2552 -DHOST = 127.0.0.1":

1号航站楼:

$ sbt -DPORT=2551 -DHOST=127.0.0.1 "project chapter14" run

2号航站楼:

$ sbt -DPORT=2552 -DHOST=127.0.0.1 "project chapter14" run

3号航站楼

$ sbt -DPORT=2553 -DHOST=127.0.0.1 "project chapter14" run

或者如果你仍然得到相同的例外,可以使用其他一些端口。

您还可以尝试使用以下命令导出环境变量:

$ export PORT=2553

然后您只能使用以下命令运行代码:

$ sbt "project chapter14" run