I'm new at Akka Streams and I have a question.
So I have some Client (source code from official documentation below) which can handle and process data from Server .
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);
How can I add callback methods ( onComplete()
, onError()
)?
看看watchTermination
组合器,它将使流具体化一个 Future,它将完成或失败,具体取决于流是完成还是出错。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.