我是akka noob:我正在尝试使用akka-sample-cluster-scala transformatino示例并将其分解为在两台计算机上运行。
我相信我只能通过配置来做到这一点。我怀疑那是我很天真。
我也在vm中运行这些网络,因为网络设置正确,因此wierd ip范围。有一个域,所以我使用NAT和仅主机网络。这个可能是一个问题,但我相信它不会是这个。
我也从netstat知道这不是因为其他东西有端口。 nmap -p 2550 192.168.56.101表示端口在后端运行时打开
我不明白为什么前端试图连接到2551上的主机(当我确实通过2550它失败了,同样的例外(下图))
所以我拿了akka-sample-cluster-scala / src / main / resources / application.conf并将其更改为 所以在' 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'奴隶' (他们是一样的)
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
}
}
然后我希望后端运行我正在做这个
/activator "runMain sample.cluster.transfortion.TransformationBackend 2550"
在另一端
./activator "runMain sample.cluster.transformation.TransformationFrontend 2551"
我怀疑我完全糊涂了,这对任何读书都是无稽之谈。 如果你能帮助我多多赞赏。
错误是在一台机器上后端似乎开始并等待
在客户端我得到以下异常
[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)
答案 0 :(得分:1)
前端代码
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)
}
}
}
}
后端代码:
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")
}
}
前端配置:
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
}
}
后端配置:
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
}
}
也应该在这些更改之后添加,指定从执行的语句中省略端口