Scala Akka流到演员问题

Scala Akka流到演员问题,scala,akka,akka-stream,Scala,Akka,Akka Stream,我试图使用Sink.actorRefWithAck将http响应流式传输给一个参与者,但不知何故,除了init和complete MSG之外,没有任何东西发送给这个Sink参与者。不过,我可能错过了一些非常明显的东西。 “水槽演员”正在顺利启动。以下是流媒体演员的代码: override def receive: Receive = { case GetTestData(p, id) => // Get the data and pipes it to itself t

我试图使用Sink.actorRefWithAck将http响应流式传输给一个参与者,但不知何故,除了init和complete MSG之外,没有任何东西发送给这个Sink参与者。不过,我可能错过了一些非常明显的东西。 “水槽演员”正在顺利启动。以下是流媒体演员的代码:

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")
}
下面是sink 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:58530 INFO com.mcma.actors.Supervisor akka。tcp://alor-system@10.33.135.82:8000/user/supervisorActor-supervisorActor将GetTestData消息转发给TestJobActor

2018-01-25 17:26:59243 INFO com.mcma.actors.jobs.TestJob-akka。tcp://alor-system@10.33.135.82:8000/用户/监管者/testJobActor-TestJob actor已启动

2018-01-25 17:27:00052 INFO com.mcma.actors.jobs.TestJob2 akka。tcp://alor-system@10.33.135.82:8000/user/supervisorActor/testJobActor/testJob2Actor-TestJob2 actor已启动

2018-01-25 17:27:00067 INFO com.mcma.actors.jobs.TestJob2 akka。tcp://alor-system@10.33.135.82:8000/user/supervisorActor/testJobActor/testJob2Actor-testJob2Actor收到初始化接收消息

2018-01-25 17:27:00083 INFO com.mcma.actors.jobs.TestJob2 akka。tcp://alor-system@10.33.135.82:8000/user/supervisorActor/testJobActor/testJob2Actor-testJob2Actor收到完整的接收消息


想法:(1)来自
实体的
。数据字节
可能为空,或者(2)接收器参与者实际上正在通过testring块处理
,但是日志记录级别使得调试消息不可见。尝试将日志记录级别设置为DEBUG,或者将
log.DEBUG(b.utf8String)
更改为
log.info(b.utf8String)

问题是,我一次只有一行日志记录了整个json消息,它非常小,但我不明白如果我有字节流,为什么它不按字节记录?要将
源代码
按testring
段划分为有效的JSON
段,可以使用:
entity.dataBytes.via(JsonFraming.objectScanner(Int.MaxValue)).runWith(sink)
谢谢,它正确地分块json对象,并将消息逐个发送给参与者。也就是说,系统的目标只是充当一个管道:接收一个大的http响应,并在sink actor中通过http将数据流传回,从性能角度来看,什么是最好的方法?因为我认为如果我对收到的每条消息/json obj发出http请求,atm流概念就会被打破,对吗?是否有可能使用头“传输编码:分块”头来维护http连接。?