Akka HTTP遇到死信

时间:2019-01-30 05:45:05

标签: java akka

我正在使用Java使用Akka HTTP开发一个简单的REST API。在成功完成请求-响应周期后,将获得诸如此类的信息。

[INFO] [01/30/2019 10:35:04.176] [default-akka.actor.default-dispatcher-5] [akka://default/system/IO-TCP/selectors/$a/2] Message [akka.io.TcpConnection$Unregistered$] from Actor[akka://default/system/IO-TCP/selectors/$a/2#-1193182068] to Actor[akka://default/system/IO-TCP/selectors/$a/2#-1193182068] was not delivered. [1] dead letters encountered. If this is not an expected behavior, then [Actor[akka://default/system/IO-TCP/selectors/$a/2#-1193182068]] may have terminated unexpectedly, This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.

如果这是正常情况,我想停止在控制台上打印。如果这是某种错误;怎么处理呢?这是我的代码。

ActorSystem system = ActorSystem.create();
Materializer materializer = ActorMaterializer.create(system);
Function<HttpRequest, HttpResponse> requestHandler = new Function<HttpRequest, HttpResponse>(){
        private static final long serialVersionUID = 1L;

        @Override
        public HttpResponse apply(HttpRequest request) throws Exception {

            return HttpResponse.create().withEntity("HelloWorld");
        }};
Source<IncomingConnection, CompletionStage<ServerBinding>> serverSource = Http.get(system)
       .bind(ConnectHttp.toHost("0.0.0.0", 8080), materializer);
CompletionStage<ServerBinding> serverBindingFuture = serverSource.to(Sink.foreach(connection -> {
        System.out.println("Accepted new connection from " + connection.remoteAddress());
        connection.handleWithSyncHandler(requestHandler, materializer);

        })).run(materializer);

1 个答案:

答案 0 :(得分:0)

将自定义配置传递给actor系统解决了我的问题。

final Config config = ConfigFactory.load().withValue("akka.log-dead-letters", ConfigValueFactory.fromAnyRef("off"));
                    
ActorSystem system = ActorSystem.create("mysystem", config);