如何在 akka 类型的 actor 中发出客户端 http 请求?
How do I make a client http request inside of a akka typed actor?
似乎http客户端请求API只针对经典演员:
val responseFuture: Future[HttpResponse] = Http().singleRequest(HttpRequest(uri = "http://akka.io"))
responseFuture
.onComplete {
case Success(res) => println(res)
case Failure(_) => sys.error("something wrong")
}
我有一个 akka 类型的演员,但不确定如何向我的 API 发出外部 http 请求。
当我在输入的 actor 中添加上面的内容时,出现了这个错误:
could not find implicit value for parameter system: akka.actor.ClassicActorSystemProvider
我有什么选择?
类型化 actor 系统可以很容易地转换为经典系统,并用于通过 akka-http
发送您的 http 请求。
例如,如果有一个akka.actor.typed.ActorSystem
类型的val,您可以通过以下方式将其转换为经典类型
val system: akka.actor.typed.ActorSystem[_] = ???
implicit val classic = system.classicSystem
所以现在,任何需要 implicit actorSystem: akka.actor.ActorSystem
方法参数的方法都可以使用。
并且从类型化的 actor 中,您可以获得对上下文的引用,然后是类型化的 actor 系统,然后转换为经典的系统
val behavior = Behaviors.setup[Int] { ctx =>
implicit val classic = ctx.system.classicSystem
???
}
似乎http客户端请求API只针对经典演员:
val responseFuture: Future[HttpResponse] = Http().singleRequest(HttpRequest(uri = "http://akka.io"))
responseFuture
.onComplete {
case Success(res) => println(res)
case Failure(_) => sys.error("something wrong")
}
我有一个 akka 类型的演员,但不确定如何向我的 API 发出外部 http 请求。
当我在输入的 actor 中添加上面的内容时,出现了这个错误:
could not find implicit value for parameter system: akka.actor.ClassicActorSystemProvider
我有什么选择?
类型化 actor 系统可以很容易地转换为经典系统,并用于通过 akka-http
发送您的 http 请求。
例如,如果有一个akka.actor.typed.ActorSystem
类型的val,您可以通过以下方式将其转换为经典类型
val system: akka.actor.typed.ActorSystem[_] = ???
implicit val classic = system.classicSystem
所以现在,任何需要 implicit actorSystem: akka.actor.ActorSystem
方法参数的方法都可以使用。
并且从类型化的 actor 中,您可以获得对上下文的引用,然后是类型化的 actor 系统,然后转换为经典的系统
val behavior = Behaviors.setup[Int] { ctx =>
implicit val classic = ctx.system.classicSystem
???
}