【问题标题】:ActorPublisher as Comet Event Source in Play ApplicationActorPublisher 作为 Play 应用程序中的彗星事件源
【发布时间】:2016-06-08 10:30:35
【问题描述】:

我正在尝试编写一个连接到 Amazon Kinesis 流的 Actor,然后将通过 Comet 接收到的任何消息中继到 Web UI。我为此使用 Source.actorPublisher 并使用 json 方法和 Comet in Play 描述 here。我使用 Source.tick() 让事件工作得很好,但是当我尝试使用 ActorPublisher 时,Actor 似乎从未像预期的那样发送任何 Request 消息。数据请求通常如何通过 Akka 流发送?我正在使用 Play Framework 的 v2.5。

我的控制器代码:

def subDeviceSeen(id: Id): Action[AnyContent] = Action {
  val deviceSeenSource: Source[DeviceSeenMessage, ActorRef] = Source.actorPublisher(DeviceSeenEventActor.props)
  Ok.chunked(deviceSeenSource
    .filter(m => m.id == id)
      .map(Json.toJson(_))
        via Comet.json("parent.deviceSeen")).as(ContentTypes.JSON)
}

我在上面做错了什么吗?这是我的演员代码:

object DeviceSeenEventActor {
  def props: Props = Props[DeviceSeenEventActor]
}

class DeviceSeenEventActor extends ActorPublisher[DeviceSeenMessage] {

implicit val mat = ActorMaterializer()(context)

val log = Logging(context.system, this)

def receive: Receive = {
  case Request => log.debug("Received request message")
                  initKinesis()
                  context.become(run)
  case Cancel => context.stop(self)
}

def run: Receive = {
  case vsm:DeviceSeenMessage => onNext(vsm)
                                 log.debug("Received request message")
                                 onCompleteThenStop() //we are currently only interested in one message
  case _:Any                  => log.warning("Unknown message received by event Actor")
}

private def initKinesis() = {
  //init kinesis, a worker is created and given a reference to this Actor.
  //The reference is used to send messages to the actor.
}

}

永远不会显示“收到的请求消息”日志行。我错过了一些隐含的吗?播放控制台中没有任何警告或任何其他明显的显示。

【问题讨论】:

    标签: scala playframework akka comet


    【解决方案1】:

    问题是我在 case Request => ... 而不是 case Request() => ... 上进行模式匹配。由于我的 receive() 方法中没有默认情况,因此该消息被 Actor 简单地丢弃了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-28
      • 2015-07-15
      • 2011-05-29
      • 1970-01-01
      • 2013-01-14
      • 1970-01-01
      • 2010-12-26
      • 1970-01-01
      相关资源
      最近更新 更多