我正在尝试使用Sink.actorRefWithAck将一个http响应流式传输给一个actor,但不知何故没有发送给这个接收器actor但是init和完整的msgs。我可能错过了一些非常明显的东西。 接收器演员很好地发起了。以下是流媒体演员的代码:
override def receive: Receive = {
case GetTestData(p, id) =>
// Get the data and pipes it to itself through a message as recommended
http.singleRequest(HttpRequest(uri = uri.format(p, id)))
.pipeTo(self)
case HttpResponse(StatusCodes.OK, _, entity, _) =>
// Sink as actorRef
val sink = Sink.actorRefWithAck(context.actorOf(TestJob2.props(), "testJob2Actor"), Init, Ack, Complete)
// Pipe the response body to the actor sink
entity.dataBytes.runWith(sink)
case resp @ HttpResponse(code, _, _, _) =>
log.error("Request to test job failed, response code: " + code)
// Discard the flow to avoid backpressure
resp.discardEntityBytes()
case _ => log.warning("Unexpected message in TestJobActor")
}
这里是接收器actor的代码:
override def receive: Receive = {
case Init =>
log.info("TestJob2Actor got init sink message")
sender ! Ack
case Complete => log.info("TestJob2Actor got complete sink message")
case b: ByteString =>
log.debug(b.utf8String)
sender ! Ack
case _ => log.warning("Unexpected message in TestJob2Actor")
}
输出:
2018-01-25 17:26:58,530 INFO com.mcma.actors.Supervisor akka.tcp://alor-system@10.33.135.82:8000 / user / supervisorActor - SupervisorActor将GetTestData消息转发给TestJobActor
2018-01-25 17:26:59,243 INFO com.mcma.actors.jobs.TestJob akka.tcp://alor-system@10.33.135.82:8000 / user / supervisorActor / testJobActor - TestJob actor started
2018-01-25 17:27:00,052 INFO com.mcma.actors.jobs.TestJob2 akka.tcp://alor-system@10.33.135.82:8000 / user / supervisorActor / testJobActor / testJob2Actor - TestJob2 actor started
2018-01-25 17:27:00,067 INFO com.mcma.actors.jobs.TestJob2 akka.tcp://alor-system@10.33.135.82:8000 / user / supervisorActor / testJobActor / testJob2Actor - TestJob2Actor get init接收消息
2018-01-25 17:27:00,083 INFO com.mcma.actors.jobs.TestJob2 akka.tcp://alor-system@10.33.135.82:8000 / user / supervisorActor / testJobActor / testJob2Actor - TestJob2Actor完成接收消息
答案 0 :(得分:4)
想法:(1)来自Source
的{{1}}可能为空,或者(2)接收者实际上正在处理entity.dataBytes
块,但是日志记录级别是调试消息不可见。尝试将您的日志记录级别设置为DEBUG,或将ByteString
更改为log.debug(b.utf8String)
。