使用 play WS 2.5.x from Akka actor
Use play WS 2.5.x from Akka actor
我将 akka 与 java 一起使用,并正在寻找一种在 akka actor 中使用异步播放 WS api 的方法。
在玩 WS 2.4.x 方法 WSRequest.get()
returns 一个 F.Promise
可以很容易地转换为 Scala Future
然后用 akka.pattern.Patterns.pipe
发送给某个 akka actor,以便将 http 响应作为 akka 消息接收。
在玩 WS 2.5.x 方法 WSRequest.get()
returns a CompletionStage
我不知道如何将它传递给 Akka 演员。
那么如何在 Akka actor 中正确使用 play WS 2.5.x api?
While Play 2.4 was cross compiled against both Scala 2.10 and Scala
2.11, this new release of Play is only available for Scala 2.11. The reason for dropping Scala 2.10 support is that Play has a new library
dependency on scala-java8-compat, which is only available for Scala
2.11. This library makes it easy to convert from and to common Scala and Java8 types, and hence it’s valuable to simplify the Play core.
Furthermore, you may also find it handy to use in your own Play
project. For example, if you need to convert Scala Future instances
into Java CompletionStage (or the other way around).
import static scala.compat.java8.FutureConverters.*;
...
final Promise<String> p = promise();
final Future<String> sf = p.future();
final CompletionStage<String> cs = toJava(sf);
Future<String> sf1 = toScala(cs);
我将 akka 与 java 一起使用,并正在寻找一种在 akka actor 中使用异步播放 WS api 的方法。
在玩 WS 2.4.x 方法 WSRequest.get()
returns 一个 F.Promise
可以很容易地转换为 Scala Future
然后用 akka.pattern.Patterns.pipe
发送给某个 akka actor,以便将 http 响应作为 akka 消息接收。
在玩 WS 2.5.x 方法 WSRequest.get()
returns a CompletionStage
我不知道如何将它传递给 Akka 演员。
那么如何在 Akka actor 中正确使用 play WS 2.5.x api?
While Play 2.4 was cross compiled against both Scala 2.10 and Scala 2.11, this new release of Play is only available for Scala 2.11. The reason for dropping Scala 2.10 support is that Play has a new library dependency on scala-java8-compat, which is only available for Scala 2.11. This library makes it easy to convert from and to common Scala and Java8 types, and hence it’s valuable to simplify the Play core. Furthermore, you may also find it handy to use in your own Play project. For example, if you need to convert Scala Future instances into Java CompletionStage (or the other way around).
import static scala.compat.java8.FutureConverters.*;
...
final Promise<String> p = promise();
final Future<String> sf = p.future();
final CompletionStage<String> cs = toJava(sf);
Future<String> sf1 = toScala(cs);