I am using Akka HTTP for REST support, and I need to use Actors in another part of the server I'm developing. My understanding is that one typically needs to use exactly ONE ActorSystem instance throughout one's application. From the definition of akka.http.scaladsl.Http.apply(), it seems that when I use the Http method, as in the snippet from my code below --
val service: FooRestService = new FooRestService()
Http(). bindAndHandle(service.route, "localhost", 8080) // something is supplying the imply method w/ implicit ActorSystem !
--- somehow the Http object's apply() method is getting supplied with an implicit ActorSystem instance... For easy reference, Http.apply() is defined like this:
package akka.http.scaladsl.Http
...
object Http {
...
def apply()(implicit system: ActorSystem): HttpExt = super.apply(system)
Since I need to stick to exactly one ActorSystem instance, I want to supply the other (non-REST) Actor-based code in my system with the SAME reference as the one that is being supplied to the Http apply() method.
I guessed that my code must be doing a package import of a package with a package object with an implicit ActorSystem, or there must be some other way this implicit is slipping in like a ninja in the dead of night. I've poked around quite a bit, but couldn't figure it out ;^(
Any suggestions much appreciated !
Not sure I fully understood what the problem is but in your every actor you have context: ActorContext
. You can obtain ActorSystem
from context.system
. Thus you don't need to explicitly pass ActorSystem
around.