Akka 使用文件上载Actor进行喷洒路由

Akka 使用文件上载Actor进行喷洒路由,akka,spray,Akka,Spray,我有一个利用Spray路由的现有Spray应用程序,最近我添加了一个文件流上传演员 我不明白的是如何将我现有的根HttpService actor与我的文件上传actor结合起来,后者不扩展HttpService 我现有的根服务参与者如下所示: class RootService extends Actor with HttpService with Routes with ActorLogging { def receive = runRoute { routes } }

我有一个利用Spray路由的现有Spray应用程序,最近我添加了一个文件流上传演员

我不明白的是如何将我现有的根HttpService actor与我的文件上传actor结合起来,后者不扩展HttpService

我现有的根服务参与者如下所示:

class RootService extends Actor with HttpService with Routes with ActorLogging {
  def receive = runRoute {
      routes
  }
}
class FileUploadService extends Actor with Logging {
  def receive = {
    case part @ HttpRequest(POST, Uri.Path("/upload"), headers, entity: HttpEntity.NonEmpty, protocol) => {
      val parts = part.asPartStream()
      val client = sender
      val handler = context.actorOf(Props(new FileUploadHandler(client, parts.head.asInstanceOf[ChunkedRequestStart])))
      parts.tail.foreach(handler !)
    }
    case start @ ChunkedRequestStart(HttpRequest(POST, Uri.Path("/upload"), _, _, _)) => {
      val client = sender
      val handler = context.actorOf(Props(new FileUploadHandler(client, start)))
      sender ! RegisterChunkHandler(handler)
    }
  }
}
我的文件上传演员是这样的:

class RootService extends Actor with HttpService with Routes with ActorLogging {
  def receive = runRoute {
      routes
  }
}
class FileUploadService extends Actor with Logging {
  def receive = {
    case part @ HttpRequest(POST, Uri.Path("/upload"), headers, entity: HttpEntity.NonEmpty, protocol) => {
      val parts = part.asPartStream()
      val client = sender
      val handler = context.actorOf(Props(new FileUploadHandler(client, parts.head.asInstanceOf[ChunkedRequestStart])))
      parts.tail.foreach(handler !)
    }
    case start @ ChunkedRequestStart(HttpRequest(POST, Uri.Path("/upload"), _, _, _)) => {
      val client = sender
      val handler = context.actorOf(Props(new FileUploadHandler(client, start)))
      sender ! RegisterChunkHandler(handler)
    }
  }
}
我已尝试按如下方式修改我的根服务参与者:

class RootService extends Actor with HttpService with Routes with ActorLogging {
  val fileUploadActor = context.actorOf(Props[FileUploadService], "fileUploadActor")
  def receive = runRoute {
    pathPrefix("upload") {
        fileUploadActor ! _.request
    } ~ {
      route
    }
  }
}
但这不能正常工作。最终,响应永远不会返回给客户机(即使我指定了询问与告知)

对工作实施有何建议


谢谢

在RootService中,将RequestContext发送给上传参与者:

def receive = runRoute {
 pathPrefix("upload") {
   ctx => fileUploadActor ! ctx
 }
}
然后在文件上传服务中,您可以使用与RootService相同的方式使用runRoute,并在该服务中完成请求。如果您有对RequestContext的引用,则无需回复RootService