0

我正在努力学习akka-http和研究他们的榜样

这是我的代码的样子

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

和通知者为

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")
      }
  }

正如你所看到的,我ActorSystem每一次Actor创作都会创造新的,这很糟糕吗?我在akka docs中读到你不应该有很多ActorSystems

我怎样才能避免这种情况?在施工期间将其作为参数传递?

4

1 回答 1

5

ActorSystem你每次都创造新的肯定是错误的!ActorSystem每个演员都可以使用context

context.system
于 2015-08-04T22:08:08.110 回答