Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala 价值不是akka.routing.Router的成员_Scala_Akka - Fatal编程技术网

Scala 价值不是akka.routing.Router的成员

Scala 价值不是akka.routing.Router的成员,scala,akka,Scala,Akka,我一直在努力建立和运行一些Akka示例,遇到了一个给我带来不少麻烦的问题。让我感到奇怪的是,文档中直接出现的代码不起作用 import akka.actor._ import akka.routing.{ ActorRefRoutee, RoundRobinRoutingLogic, Router, Broadcast } object TransformationManager { case class ProcessFile(fileIt:Iterator[String]) ca

我一直在努力建立和运行一些Akka示例,遇到了一个给我带来不少麻烦的问题。让我感到奇怪的是,文档中直接出现的代码不起作用

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

我不知道为什么这不起作用。

没有
路由器上
。您可以使用
router.route
发送消息

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.route(msg, sender())

提到docs,路由器可能是一个参与者,然后
应该可以工作,但不一定要工作,这取决于您如何创建它。请在此处阅读更多信息:

在Akka文件的第3.6.4节中,他们提供了一个广播消息被发送到路由器的示例,以便一次向所有路由器发送消息。他们的代码不正确吗?顺便说一句,当我把广播放在msg中时,这对我很有用,非常感谢。奇怪的是,这些文档的代码不正确。我想它只是被弃用了。