就像没有收到 Array[Byte] 的演员一样?

Akka actors not receiving Array[Byte]?

我正在尝试编写一个 actor 来计算它收到的消息,并在它达到特定数量的消息时打印出来。

当我将消息作为字符串发送给 actor 时,我成功了,但是当我尝试发送 Array[Bytes] 时,actor 没有执行它的接收功能,但它也没有' t 调用它的 catch else 案例。

有效处理字符串的代码:

class CountingActor extends Actor {

  val log = Logging(context.system, this)
  val startTime = System.currentTimeMillis
  var count = 0
  val actorName = self.path.name

  def Count: Actor.Receive = {
    case message: String =>
      count += 1
      if(count % 50000 == 0 && count != 0){
        var elapsed = (System.currentTimeMillis - startTime) / 1000.0
        var mps = count / elapsed
        log.info(s"Processed $count messages in $elapsed ($mps msg/s) in $actorName")
      }

    case _ => log.info("Something happened and I dont know, it wasn't a string")
  }

  def receive = Count

}

处理失败的代码和Array[Byte]是一模一样的,只是我指定大小写为Array[Byte]而不是string。

class CountingActor extends Actor {

  val log = Logging(context.system, this)
  val startTime = System.currentTimeMillis
  var count = 0
  val actorName = self.path.name

  def Count: Actor.Receive = {
    case message: Array[Byte] =>
      count += 1
      if(count % 50000 == 0 && count != 0){
        var elapsed = (System.currentTimeMillis - startTime) / 1000.0
        var mps = count / elapsed
        log.info(s"Processed $count messages in $elapsed ($mps msg/s) in $actorName")
      }

    case _ => log.info("Something happened and I dont know, it wasn't a string")
  }

  def receive = Count

}

我试过这种情况

  val s = ActorSystem()
  val ca = s.actorOf(Props[CountingActor])
  ca ! Array[Byte](1, 1, 0)

而且效果很好。尝试在

之后添加额外的日志记录
case message: Array[Byte] =>

看到这个。现在,如果 count 小于 50000,您的代码不会对此消息显示任何可见的反应,那么您如何知道 "the actor doesn't perform it's receive function"?