简体   繁体   English

Akka Typed 演员在玩 websocket

[英]Akka Typed actor in play websocket

I'm developing a web-socket application in play and using actor based websocket implementation according to their official tutorial ( https://www.playframework.com/documentation/2.8.x/JavaWebSockets )我正在根据他们的官方教程( https://www.playframework.com/documentation/2.8.x/JavaWebSockets )开发一个正在运行的网络套接字应用程序并使用基于演员的网络套接字实现

In controller在控制器中

 public WebSocket socket() {
    System.out.println("socket connecton received");
    return WebSocket.Text.accept(
            request -> ActorFlow.actorRef(WebSocketActor::props, actorSystem, materializer));
}

WebSocketActor is implemented with Typed actors as below WebSocketActor 是使用 Typed actor 实现的,如下所示

public class WebSocketActor extends AbstractBehavior<String> {

But the issue is it is giving me following error Incompatible types: ActorRef is not convertible to ActorRef and it seems like ActorFlow.actorRef is only allows un-typed actors.但问题是它给了我以下错误不兼容的类型:ActorRef 不能转换为 ActorRef并且似乎 ActorFlow.actorRef 只允许无类型的演员。

How can I use a Typed Actor with above implementation.如何使用具有上述实现的类型化 Actor。

When there are missing APIs for typed (I think this is the case with the Play ActorFlow) you can adapt the new typed APIs to the classic ones using akka.actor.typed.javadsl.Adapter , like so: Adapter.toClassic(typedActorRef)当缺少类型化 API 时(我认为 Play ActorFlow 就是这种情况),您可以使用akka.actor.typed.javadsl.Adapter将新类型化 API 改编为经典 API,如下所示: Adapter.toClassic(typedActorRef)

More docs on coexisting typed and classic APIs here: https://doc.akka.io/docs/akka/current/typed/coexisting.html有关共存类型化和经典 API 的更多文档,请访问: https : //doc.akka.io/docs/akka/current/typed/coexisting.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM