문제

I am an akka noob: am attempting to take the akka-sample-cluster-scala transformatino example and break it to run across 2 machines.

I believe i can do this just through config. I suspect that is me being very naive.

I am also running these in vm's that have the network set up correctly hence the wierd ip ranges. There is a domain so i am using both a NAT and host only network. This could be an issue however i am fairly certain it wont be this.

I also know from netstat this isn't due to something else having the port. nmap -p 2550 192.168.56.101 says the port is open whilst backend is running

i dont get why the front end is trying to connect to the host on 2551 though (and when i do pass it 2550 it fails with teh same exception (below))

So I took the akka-sample-cluster-scala/src/main/resources/application.conf and changed it to this So on the 'master'

akka {
  actor {
    provider = "akka.cluster.ClusterActorRefProvider"
  }
  remote {
    log-remote-lifecycle-events = off
    netty.tcp {
      hostname = "192.168.56.101"
      port = 2550
    }
  }

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

    auto-down-unreachable-after = 10s
  }
}

on the 'slave' (they are the same)

akka {
  actor {
    provider = "akka.cluster.ClusterActorRefProvider"
  }
  remote {
    log-remote-lifecycle-events = off
    netty.tcp {
      hostname = "192.168.56.101"
      port = 2550
    }
  }

  cluster {
    seed-nodes = [
      "akka.tcp://ClusterSystem@192.168.56.102:2551",
      "akka.tcp://ClusterSystem@127.168.56.102:2552"]

    auto-down-unreachable-after = 10s
  }
}

then where i want the backend running i am doing this

/activator "runMain sample.cluster.transfortion.TransformationBackend 2550"

and on other end

./activator "runMain sample.cluster.transformation.TransformationFrontend 2551"

I suspect i am utterly confused and this is nonsense to anyone reading. If you can help enlighten me much appreciated.

The error is that on one machine the backend it seems to start and sits there waiting

on the client end i am getting the following exception

[info] [INFO] [04/24/2014 15:06:23.989] [main] [Remoting] Starting remoting
[error] Exception in thread "main" org.jboss.netty.channel.ChannelException: Failed to bind to: /192.168.56.101:2551
[error]     at org.jboss.netty.bootstrap.ServerBootstrap.bind(ServerBootstrap.java:272)
[error]     at akka.remote.transport.netty.NettyTransport$$anonfun$listen$1.apply(NettyTransport.scala:392)
[error]     at akka.remote.transport.netty.NettyTransport$$anonfun$listen$1.apply(NettyTransport.scala:389)
[error]     at scala.util.Success$$anonfun$map$1.apply(Try.scala:206)
[error]     at scala.util.Try$.apply(Try.scala:161)
[error]     at scala.util.Success.map(Try.scala:206)
[error]     at scala.concurrent.Future$$anonfun$map$1.apply(Future.scala:235)
[error]     at scala.concurrent.Future$$anonfun$map$1.apply(Future.scala:235)
[error]     at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32)
[error]     at akka.dispatch.BatchingExecutor$Batch$$anonfun$run$1.processBatch$1(BatchingExecutor.scala:67)
[error]     at akka.dispatch.BatchingExecutor$Batch$$anonfun$run$1.apply$mcV$sp(BatchingExecutor.scala:82)
[error]     at akka.dispatch.BatchingExecutor$Batch$$anonfun$run$1.apply(BatchingExecutor.scala:59)
[error]     at akka.dispatch.BatchingExecutor$Batch$$anonfun$run$1.apply(BatchingExecutor.scala:59)
[error]     at scala.concurrent.BlockContext$.withBlockContext(BlockContext.scala:72)
[error]     at akka.dispatch.BatchingExecutor$Batch.run(BatchingExecutor.scala:58)
[error]     at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:41)
[error]     at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:393)
[error]     at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
[error]     at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
[info] [INFO] [04/24/2014 15:06:24.140] [ClusterSystem-akka.remote.default-remote-dispatcher-15] [akka://ClusterSystem/system/remoting-terminator] Shutting down remote daemon.
[error]     at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
[error]     at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
[error] Caused by: java.net.BindException: Cannot assign requested address
[error]     at sun.nio.ch.Net.bind0(Native Method)
[error]     at sun.nio.ch.Net.bind(Net.java:444)
[error]     at sun.nio.ch.Net.bind(Net.java:436)
[error]     at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:214)
[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:372)
[error]     at org.jboss.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:296)
[error]     at org.jboss.netty.channel.socket.nio.NioServerBoss.run(NioServerBoss.java:42)
[error]     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
[error]     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
[info] [INFO] [04/24/2014 15:06:24.146] [ClusterSystem-akka.remote.default-remote-dispatcher-15] [akka://ClusterSystem/system/remoting-terminator] Remote daemon shut down; proceeding with flushing remote transports.
[error]     at java.lang.Thread.run(Thread.java:744)
도움이 되었습니까?

해결책

Frontend code

object TransformationFrontend {
  def main(args: Array[String]): Unit = {
    // Override the configuration of the port when specified as program argument
    val port = if (args.isEmpty) "0" else args(0)
    val config = ConfigFactory.load()

    val system = ActorSystem("ClusterSystem", config)
    val frontend = system.actorOf(Props[TransformationFrontend], name = "frontend")

    val counter = new AtomicInteger
    import system.dispatcher
    system.scheduler.schedule(2.seconds, 2.seconds) {
      implicit val timeout = Timeout(5 seconds)
      (frontend ? TransformationJob("hello-" + counter.incrementAndGet())) onSuccess {
        case result => println(result)
      }
    }

  }
}

Backend code:

object TransformationBackend {
  def main(args: Array[String]): Unit = {
    // Override the configuration of the port when specified as program argument
    val port = if (args.isEmpty) "0" else args(0)
    val config = ConfigFactory.load()

    val system = ActorSystem("ClusterSystem", config)
    system.actorOf(Props[TransformationBackend], name = "backend")
  }
}

Front end config:

akka {
  actor {
    provider = "akka.cluster.ClusterActorRefProvider"
  }
  remote {
    log-remote-lifecycle-events = off
    netty.tcp {
      hostname = "192.168.56.102"
      port = 2551
    }
  }

  cluster {
    roles = [frontend]
    seed-nodes = [
      "akka.tcp://ClusterSystem@192.168.56.102:2551"]

    auto-down-unreachable-after = 10s
  }
}

backend config:

akka {
  actor {
    provider = "akka.cluster.ClusterActorRefProvider"
  }
  remote {
    log-remote-lifecycle-events = off
    netty.tcp {
      hostname = "192.168.56.101"
      port = 2550
    }
  }

  cluster {
    roles = [backend]
    seed-nodes = [
      "akka.tcp://ClusterSystem@192.168.56.102:2551"]

    auto-down-unreachable-after = 10s
  }
}

should also add after these changes specifying the port was omitted from the statements to execute

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top