第 9 章 检测死连接
有时,客户端会意外停止,且没有机会清理其资源。如果发生了这种情况,它可能会让资源处于故障状态,并导致代理内存不足或其他系统资源。代理检测到客户端的连接没有在垃圾回收时正确关闭。然后,连接会关闭,并将类似以下的消息写入到日志中。日志捕获客户端会话实例化的代码的确切行。这可让您识别错误并更正它。
[Finalizer] 20:14:43,244 WARNING [org.apache.activemq.artemis.core.client.impl.DelegatingSession] I'm closing a JMS Conection you left open. Please make sure you close all connections explicitly before let
ting them go out of scope!
[Finalizer] 20:14:43,244 WARNING [org.apache.activemq.artemis.core.client.impl.DelegatingSession] The session you didn't close was created here:
java.lang.Exception
at org.apache.activemq.artemis.core.client.impl.DelegatingSession.<init>(DelegatingSession.java:83)
at org.acme.yourproject.YourClass (YourClass.java:666)
- 1
- 连接实例化的客户端代码中的行。
9.1. Connection Time-To-Live 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
由于客户端和服务器之间的网络连接可能会失败,然后恢复在线,因此 AMQ Broker 会等待清理不活跃的服务器端资源。这个等待周期被称为生存时间(TTL)。基于网络的连接的默认 TTL 为 60000 毫秒(1 分钟)。in-VM 连接上的默认 TTL 是 -1,这意味着代理永远不会超时到代理端的连接。
在代理中配置 Time-To-Live
如果您不希望客户端指定自己的连接 TTL,您可以在代理端设置全局值。这可以通过在代理配置中指定 connection-ttl-override 元素来实现。
检查 TTL 违反连接的逻辑在代理上定期运行,具体由 connection-ttl-check-interval 元素决定。
流程
通过添加
connection-ttl-override配置元素,再提供 time-to-live 的值来编辑 <broker_instance_dir> /etc/broker.xml。<configuration> <core> ... <connection-ttl-override>30000</connection-ttl-override>1 <connection-ttl-check-interval>1000</connection-ttl-check-interval>2 ... </core> </configuration>