繁体   English   中英

AWS JAVA IoT 客户端每 10 分钟重新连接一次

[英]AWS JAVA IoT client reconnects every 10 minutes

我在 JAVA 中使用 IoT SDK。 当我的应用程序启动时,它连接到 AWS 的 IoT 核心:

iotClient = new AWSIotMqttClient(. . .);            
iotClient.connect();

但是在应用程序启动后,我在日志中看到一个非常奇怪的行为,它每 10 分钟发生一次:

[pool-8-thread-1] com.amazonaws.services.iot.client.core.AwsIotConnection.onConnectionSuccess Connection successfully established
[pool-8-thread-1] com.amazonaws.services.iot.client.core.AbstractAwsIotClient.onConnectionSuccess Client connection active: <client ID>
[pool-8-thread-1] com.amazonaws.services.iot.client.core.AwsIotConnection.onConnectionFailure Connection temporarily lost
[pool-8-thread-1] com.amazonaws.services.iot.client.core.AbstractAwsIotClient.onConnectionFailure Client connection lost: <client ID>
[pool-8-thread-1] com.amazonaws.services.iot.client.core.AwsIotConnection$1.run Connection is being retried
[pool-8-thread-1] com.amazonaws.services.iot.client.core.AwsIotConnection.onConnectionSuccess Connection successfully established
[pool-8-thread-1] com.amazonaws.services.iot.client.core.AbstractAwsIotClient.onConnectionSuccess Client connection active: <client ID>

如何禁用每 10 分钟重新连接一次? 我在 CONNECTED/DISCONNECTED 主题上使用 IoT 规则,因此每 10 分钟重新连接一次,每 10 分钟触发一次此规则......

有同样的问题,仅在我的 EKS Kubernetes 集群上,但不在我的本地开发计算机上。 我发现java lib 的默认keepalive 间隔是600000 毫秒或10 分钟。 这不是某些文档所声明的。

我的集群上使用的 NAT 具有 350 秒的修复空闲超时。 所以连接会断开。

我将其更改为较低的值(例如 30000 毫秒)。

iotClient.setKeepAliveInterval(30000);

现在这似乎有效。

我不知道为什么,但这是我的解决方案:

iotClient = new AWSIotMqttClient(. . .);    
        
iotClient.setKeepAliveInterval(0);

iotClient.connect();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM