0
votes

I'm trying to implement the 3 seed cluster sample application as mentioned in akka in action book.

The example is about creating the 3 seen nodes and joining the nodes as cluster.

This is my seed.conf file.

My Application that starts the ActorSystem is here.

The Author mentioned to start 3 terminals with the below commands

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

and run the app.Main in chapter14 project.

When the run the first the any of the above commands the first actor system starts successfully.

When I start the next any of the 2 remaining commands, I always get the below error. But as per author, these 3 should form cluster.

$ 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

And the already started(first node which is started) node gives the below warning message -

[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://[email protected]:2552/system/endpointManager/reliableEndpointWriter-akka.tcp%3A%2F%2Fwords%40127.0.0.1%3A2551-0] Association with remote system [akka.tcp://[email protected]:2551] has failed, address is now gated for [5000] ms. Reason: [Association failed with [akka.tcp://[email protected]: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://[email protected]:2552/system/endpointManager/reliableEndpointWriter-akka.tcp%3A%2F%2Fwords%40127.0.0.1%3A2553-1] Association with remote system [akka.tcp://[email protected]:2553] has failed, address is now gated for [5000] ms. Reason: [Association failed with [akka.tcp://[email protected]:2553]] Caused by: [Connection refused: /127.0.0.1:2553]
1

1 Answers

0
votes

As I can see in logs, the application is not able to find port free.

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

Probably you are trying to bind the netty port on same port more than once.

As a solution of this you can try to run the application using the following command rather than "sbt -DPORT=2552 -DHOST=127.0.0.1":

Terminal 1:

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

Terminal 2:

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

Terminal 3:

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

Or with some other ports if you still get the same exception.

You can also try to export environment variables using the following command:

$ export PORT=2553

and then you can run the code using the following command only:

$ sbt "project chapter14" run