我有一个处理 WebSocket 请求的 Play 应用程序。路由文件包含这一行:
GET /testsocket controllers.HomeController.defaultRoomSocket
一个已经工作的同步版本如下所示:(改编自 2.7.x 文档)
public WebSocket defaultRoomSocket() {
return WebSocket.Text.accept(
request -> ActorFlow.actorRef(MyWebSocketActor::props, actorSystem, materializer));
}
如https://www.playframework.com/documentation/2.7.x/JavaWebSockets#Accepting-a-WebSocket-asynchronously所述,我将签名更改为
public CompletionStage<WebSocket> defaultRoomSocket(){
//returning a CompletionStage here, using the "ask pattern"
//to get the needed Flow from an other Actor
}
从这里我遇到了以下问题:
Cannot use a method returning java.util.concurrent.CompletionStage[play.mvc.WebSocket] as a Handler for requests
此外,正如文档所建议的那样,“WebSocket”没有类型参数。接受 WebSocket 请求异步的合适方法是什么?
翻翻过去那场雪
相关分类