[英]My log messages are working for one file with akka typed, but not for classic actor
[英]Classic actor system sending messages to a akka typed actor
在我的應用程序中,我既有經典的演員系統,也有一個 typedGuardian(使用 akka 類型)。
implicit val system = akka.actor.ActorSystem("my-classic-actor-system")
implicit val typedGuardian: ActorRef[Any] =
system.spawn(HttpWebsocketServer(), "HttpServer")
Poly.startProcessor(?????) // pass in WebSocketIn here which is a typed actor
我的 akka 類型設置從下面的演員開始,我需要以某種方式將客戶端 webSockedIn akka 類型的演員作為參數傳遞給我的 Poly.startProcessor 經典演員。 我需要這樣做,因為我需要將消息從這個內部發送到 webSocketIn,這樣我就可以在我的 HttpWebsocketServer 內部處理這些消息。
HttpWebsocketServer:
def apply(): Behavior[Any] = {
Behaviors.setup[Any] { context =>
implicit val ec: ExecutionContext = context.executionContext
val system = context.system
val webSockedIn = context.spawn(websock.WebSocketIn(), "WebSocketIn")
我需要以某種方式將 webSockedIn 傳遞給 Poly.startProcessor:
object Poly {
def startProcessor()(implicit system: akka.actor.ClassicActorSystemProvider): Unit = {
經典的actor系統是否有可能獲得對akka類型actor的引用並發送消息呢?
如果是這樣,我應該在哪里產生我的 websocketClientIn 這樣才有可能?
假設您控制Poly
中的實現,您可以讓startProcessor
通過system.actorSelection("/user/HttpServer")
解析typedGuardian
/ HttpWebsocketServer
演員。
這樣做之后,您可以讓HttpServer
回答websockedIn
的查詢消息(例如通過詢問模式)。
所以像
// in HttpWebsocketServer
case class ResolveWebsockedIn(replyTo: ActorRef[ActorRef[WebsocketIn.Command]]) extends Command
case ResolveWebsockedIn(replyTo) =>
replyTo ! webSockedIn
Behaviors.same
// in Poly.startProcessor
import scala.concurrent.duration._
val resolvedFut = system.actorSelection("/user/HttpServer").resolveOne
val websockedInFut = resolvedFut.flatMap { classicRef =>
import akka.actor.typed.scaladsl.adapter.ClassicActorRefOps
import akka.actor.typed.scaladsl.adapter.ClassicActorSystemOps
import akka.actor.typed.scaladsl.AskPattern._
classicRef.toTyped[HttpWebsocketServer.ResolveWebsockedIn].ask(HttpWebsocketServer.ResolveWebsockedIn(_))(10.seconds, system.toTyped.scheduler)
}
因此, websockedInFut
的未來是由webSockedIn
產生的HttpWebsocketServer
完成的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.