我是Akka Streams的新人,我有一个问题。
所以我有一些客户端(来自官方文档的源代码),可以处理和处理来自服务器的数据。
private static final ActorSystem system = ActorSystem.create("Client");
private static final Materializer materializer = ActorMaterializer.create(system);
final Flow<ByteString, ByteString, CompletionStage<Tcp.OutgoingConnection>> connection =
Tcp.get(system).outgoingConnection("127.0.0.1", 8888);
final Flow<ByteString, ByteString, NotUsed> repl =
Flow.of(ByteString.class)
.map(ByteString::utf8String)
.map(text -> {
System.out.println("Server message ->: " + text);
return ByteString.fromString(text);
});
connection.join(repl).run(materializer);
如何添加回调方法(onComplete()
,onError()
)?