2015-04-04 79 views
2

我有一个现有的喷雾应用程序利用喷雾路由和我最近添加了文件流上传演员based on the example喷雾路由与文件上传演员

我无法弄清楚的是如何将我现有的根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 { 
    val fileUploadActor = context.actorOf(Props[FileUploadService], "fileUploadActor") 
    def receive = runRoute { 
    pathPrefix("upload") { 
     fileUploadActor ! _.request 
    } ~ { 
     route 
    } 
    } 
} 

但是这不起作用。最终,响应永远不会回到客户端(即使我指定了ask vs tell)。

关于工作实现的任何建议?

谢谢!

回答

3

在RootService,发送的RequestContext到上传演员:

def receive = runRoute { 
pathPrefix("upload") { 
    ctx => fileUploadActor ! ctx 
} 
} 

然后在文件上传服务,您可以在相同的方式RootService使用runRoute,并完成服务中的请求。如果您有对RequestContext的引用,则不需要回复RootService。