[英]Best way to keep WebSocket connection alive in Akka HTTP?
If there is no message sent or received, the connection is closed after one minute. 如果没有发送或接收任何消息,则一分钟后关闭连接。
I don't want to continuously send a text message to keep the connection open like this: 我不想连续发送短信以保持连接打开,如下所示:
keepAlive(maxIdle = 10.seconds, () => TextMessage.Strict("Keep-alive message")
Is there anything in Akka HTTP that provides the natural sending of ping/pong messages? Akka HTTP中是否有任何东西可以自然发送ping / pong消息? What do I need to do? 我需要做什么?
If you don't want to manually use the keepAlive
combinator, then you can use Akka HTTP's automatic keep-alive ping support, which is enabled via settings in your application.conf
. 如果您不想手动使用keepAlive
组合器,则可以使用Akka HTTP的自动keep-aling ping支持,该支持通过application.conf
设置启用。
For the client side : 对于客户端 :
akka.http.client.websocket.periodic-keep-alive-max-idle = 10 seconds
For the server side : 对于服务器端 :
akka.http.server.websocket.periodic-keep-alive-max-idle = 10 seconds
More information is in the linked documentation. 更多信息在链接的文档中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.