简体   繁体   English

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

[英]AWS JAVA IoT client reconnects every 10 minutes

I use IoT SDK in JAVA.我在 JAVA 中使用 IoT SDK。 When my application starts, it connects to IoT core of AWS:当我的应用程序启动时,它连接到 AWS 的 IoT 核心:

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

But after application starting I see in my log a very strange behavior and it happens every 10 minutes:但是在应用程序启动后,我在日志中看到一个非常奇怪的行为,它每 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>

How can I disable reconnection every 10 minutes?如何禁用每 10 分钟重新连接一次? I use IoT Rules on CONNECTED/DISCONNECTED topic, so reconnection every 10 minutes fires this rule every 10 minutes...我在 CONNECTED/DISCONNECTED 主题上使用 IoT 规则,因此每 10 分钟重新连接一次,每 10 分钟触发一次此规则......

Had the same issue, only on my EKS Kubernetes Cluster, but not on my local dev computer.有同样的问题,仅在我的 EKS Kubernetes 集群上,但不在我的本地开发计算机上。 I found out that the Default keepalive interval of the java lib is 600000ms or 10 minutes.我发现java lib 的默认keepalive 间隔是600000 毫秒或10 分钟。 This is not what some documentation declared.这不是某些文档所声明的。

The NAT used on my cluster has a fix Idle Timeout of 350 seconds.我的集群上使用的 NAT 具有 350 秒的修复空闲超时。 So the connection would drop.所以连接会断开。

I changed it to a lower value (like 30000ms).我将其更改为较低的值(例如 30000 毫秒)。

iotClient.setKeepAliveInterval(30000);

For now this seems to work.现在这似乎有效。

I don't know why, but it is my solution:我不知道为什么,但这是我的解决方案:

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

iotClient.connect();

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

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