0

I am trying to learn akka-http and working on their example

Here is what my code looks like

  val system = ActorSystem.create("enterpriseSystem", ConfigFactory.load("application"))
  val notifier = system.actorOf(Props[Notifier], "notifier")

and Notifier as

class Notifier extends Actor with ActorLogging {

  implicit val system = ActorSystem()
  implicit val materializer = ActorMaterializer()
  import scala.concurrent.ExecutionContext.Implicits.global

  def receive = {
    case CommunicateECFailure =>
      log.info("notifying about EC Failure")
      val responseFuture: Future[HttpResponse] =
        Http().singleRequest(HttpRequest(uri = "http://localhost:8080"))

      responseFuture onComplete {
        case response =>
          log.info("response received {}", response)
          log.info("notified about EC Failure")
      }
  }

As you can see I create new ActorSystem with every Actor creation, is that bad? I read in akka docs that you should not have many ActorSystems

How can I avoid that? passing it as an argument during construction?

daydreamer
  • 87,243
  • 191
  • 450
  • 722

1 Answers1

5

You are definitely wrong in creating new ActorSystem every time! ActorSystem is available in each actor context:

context.system
ka4eli
  • 5,294
  • 3
  • 23
  • 43