我正在努力学习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
我怎样才能避免这种情况?在施工期间将其作为参数传递?