Home > Software engineering >  Akka Typed Actor cannot get UDP sender
Akka Typed Actor cannot get UDP sender

Time:11-25

In classic Akka actors there is a sender() method to get the sender. I am using akka.io.Udp to make Udp multicasts to multiple actors.

  override def preStart(): Unit = {
    super.preStart()
    val manager = Udp(context.system).manager
    println(s"Sending req to bind to ${localInet}")
    manager ! Udp.Bind(self, localInet)
  }

 override def receive: Receive = {
    case Udp.Bound(localAddress) => {
      println(s"UdpConn Actor: ${sender()}")
      println(s"Bound to ${localAddress}")
      timers.startTimerWithFixedDelay("DISCOVERY", SendDiscovery, 1.seconds)
      context.become(ready(sender()))
    }
  }

This is my version in akka classic. Is there a way to get the Udp sender actor ref in the typed version since it has no sender() version.

I tried searching for a typed version of IO and UDP but I cannot find anything on the akka docs.

CodePudding user response:

The sender is not available in Akka Typed, because it would not have a meaningful type.

As yet, there is no typed version of IO. The most idiomatic approach now would be to spawn a classic actor to interact with IO/UDP and adapt/forward messages between the typed actor and the IO/UDP actor(s).

  • Related