ActorPublisher 作为 Play 应用程序中的 Comet 事件源
ActorPublisher as Comet Event Source in Play Application
我正在尝试编写一个连接到 Amazon Kinesis 流的 Actor,然后将通过 Comet 接收到的任何消息中继到 Web UI。为此,我正在使用 Source.actorPublisher,并在描述 here 的 Comet in Play 中使用 json 方法。我使用 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.
}
}
'Received request message' 日志行从不显示。我是否遗漏了一些隐含的内容?播放控制台中没有警告或任何其他明显显示。
问题是我在 case Request => ...
而不是 case Request() => ...
上进行模式匹配。由于我的 receive()
方法中没有默认情况,消息只是被 Actor 丢弃了。
我正在尝试编写一个连接到 Amazon Kinesis 流的 Actor,然后将通过 Comet 接收到的任何消息中继到 Web UI。为此,我正在使用 Source.actorPublisher,并在描述 here 的 Comet in Play 中使用 json 方法。我使用 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.
}
}
'Received request message' 日志行从不显示。我是否遗漏了一些隐含的内容?播放控制台中没有警告或任何其他明显显示。
问题是我在 case Request => ...
而不是 case Request() => ...
上进行模式匹配。由于我的 receive()
方法中没有默认情况,消息只是被 Actor 丢弃了。