本文介绍了值!不是akka.routing.Router的成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力启动和运行一些Akka示例,并且遇到了一个给我带来很多麻烦的问题。对我来说,很奇怪的是,文档中直接出现了无法使用的代码。

I've been working on getting some Akka examples up and running and have run into an issue that is giving me quite a bit of trouble. What's so strange to me is that there is code coming straight out of the documentation that isn't working.

import akka.actor._
import akka.routing.{ ActorRefRoutee, RoundRobinRoutingLogic, Router, Broadcast }


object TransformationManager {
  case class ProcessFile(fileIt:Iterator[String])
  case class ProcessLines(lines:List[List[String]], last:Boolean = false)
  case class LinesProcessed(lines:List[List[String]], last:Boolean = false)

  case object WorkAvailable
  case object WorkRequest
}

class TransformationManager extends Actor {
  import TransformationManager._

  val workChunkSize = 10
  val workersCount = 10

 def receive = {
   case ProcessFile(fileIt) => 
   var router = {
    val routees = Vector.fill(workersCount) {
      val r = context.actorOf(Props[SampleWorker])
      context watch r
      ActorRefRoutee(r)
    }
    Router(RoundRobinRoutingLogic(), routees)
   }
   router ! Broadcast(WorkAvailable) //error here !!!!!!!!!
 }
}

在最后一行代码上,

router ! Broadcast(WorkAvailable)

我收到错误消息,

value ! is not a member of akka.routing.Router

我很茫然,为什么会这样呢?

I'm at a loss for why this isn't working.

推荐答案

在! >路由器。您使用 router.route 发送消息。

There's no ! on Router. You use router.route to send a message.

router.route(msg, sender())

这篇关于值!不是akka.routing.Router的成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 03:18