0
我正在使用這個example作爲我的出發點。如何使用不響應的Akka Java API創建TCP接收器
在這個例子中,服務器響應修改過的文本,但在我的情況下,服務器不需要響應。
看着其他類似的問題,我知道我可以傳遞Empty ByteString或使用過濾器(p - > false)不發回任何東西。但是,在這種情況下,問題是我的whenComplete塊沒有得到執行。即異常被吞噬。有沒有辦法避免這種情況?幫助讚賞!
connections.runForeach(connection -> {
System.out.println("New connection from: " + connection.remoteAddress());
final Flow<ByteString, ByteString, NotUsed> echo = Flow.of(ByteString.class)
.via(Framing.delimiter(ByteString.fromString("\n"), 256, FramingTruncation.DISALLOW))
.map(ByteString::utf8String)
.map(s -> s + "!!!\n")
.map(ByteString::fromString);
connection.handleWith(echo, mat);
}, mat).whenComplete((done,throwable) ->
{
//exception handling
}
);
在進一步的分析,我認爲這個問題是我想爲每個連接completionStage而不是Source(連接)的末尾。 – tapasvi