【问题标题】:Amazon Device SDK (MQTT Client) Disconnecting without detecting the disconnectionAmazon 设备 SDK(MQTT 客户端)在未检测到断开连接的情况下断开连接
【发布时间】:2021-09-09 00:43:31
【问题描述】:

我在 NodeJS 项目中使用 Amazon Device SDK。我专门使用 MQTT 代理和客户端。上周,一切正常。本周,我的应用程序出现连接问题。从那时到现在,我没有对任何与连接相关的代码做任何事情。

根据 AWS 端的记录,我的客户端连接,发送消息(可能会收到一些消息),然后断开连接。

根据我的 Node 客户端,客户端正在连接并保持连接状态。在客户端,没有检测到问题。我相信这是因为 AWS 将客户端解释为已断开连接,因此没有将消息路由到它。为了简化事情,我让我的客户只显示状态消息。以下是我将客户减少到的内容。我还在观察这个问题。

有时,如果我在应用程序启动后立即发送几条消息,它会收到其中几条。我有一个非常短的窗口,直到它“断开连接”(根据 AWS 日志记录)。

知道是什么原因造成的吗?

this.device = awsIot.device({
    host,
    keyPath: `${process.cwd()}/certificates/2399999999-private.pem.key`,
    certPath: `${process.cwd()}/certificates/2399999999-certificate.pem.crt`,
    caPath: `${process.cwd()}/certificates/AmazonRootCA1.pem`,
    clientId: config.clientId,
    autoResubscribe: true,
    maximumReconnectTimeMs: 1600,
    keepalive: 300,
    debug: config.mqttConnection.debug,
    enableMetrics: config.mqttConnection.enableMetrics        
});


this.device.on('error', error => {
    console.error('MQTT client error: ', error);
});

this.device.on('disconnect', () => {
    console.error(`Disconnected from MQTT broker ${host}`);
});

this.device.on('message', async (topic, payload) => {
    log(`Received MQTT message: topic "${topic}", payload "${payload.toString()}"`);


});

this.device.on('close', () => { 
    console.log('close')
});

this.device.on('error', () => { 
    console.log('error')
});

this.device.on('reconnect', () => { 
    console.log('reconnect????')
});

this.device.on('offline', () => { 
    console.log('offline❌')
});

this.device.on('connect', () => {
    console.log('connected')
    this.device.subscribe('rootTopic/#');
});

从 AWS 日志中,我得到以下信息。

[
{
    "timestamp": "2021-09-09 01:25:08.930",
    "logLevel": "INFO",
    "traceId": "7a03fe42-8b6d-0b8e-8bca-0a404e40f0ef",
    "accountId": "0000",
    "status": "Success",
    "eventType": "Connect",
    "protocol": "MQTT",
    "clientId": "000-000-000000",
    "principalId": "aaaa",
    "sourceIp": "73.43.xxx.xxx",
    "sourcePort": 55961
},
{
    "timestamp": "2021-09-09 01:25:09.056",
    "logLevel": "INFO",
    "traceId": "7e965df3-84c8-562b-51b7-48f7f8b851b5",
    "accountId": "0000",
    "status": "Success",
    "eventType": "Subscribe",
    "protocol": "MQTT",
    "topicName": "experiencemanager/#",
    "clientId": "000-000-000000",
    "principalId": "aaaa",
    "sourceIp": "73.43.xxx.xxx",
    "sourcePort": 55961
},
{
    "timestamp": "2021-09-09 01:25:29.389",
    "logLevel": "INFO",
    "traceId": "6d81fb8e-521c-f91c-aea2-3ab3e4f47549",
    "accountId": "0000",
    "status": "Success",
    "eventType": "Disconnect",
    "protocol": "MQTT",
    "clientId": "000-000-000000",
    "principalId": "aaaa",
    "sourceIp": "73.43.xxx.xxx",
    "sourcePort": 55961,
    "disconnectReason": "CONNECTION_LOST"
}
]




【问题讨论】:

    标签: amazon-web-services mqtt aws-iot


    【解决方案1】:

    本身不是答案,但我发现我遇到的问题源于 Electron 的计时器。 Electron 中的计时器功能停止运行。如果没有计时器,AWS sdk 无法检测断开连接或对某些队列进行操作。

    我还有更多的挖掘工作要做。但这不是 Amazon SDK 本身的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-23
      • 2011-07-08
      • 1970-01-01
      • 2020-01-15
      相关资源
      最近更新 更多