Node Azure IoT SDK上的sendEvent超时问题

时间:2019-08-27 18:46:59

标签: azure-iot-hub azure-iot-sdk

使用sendEvent()的超时消息无法正常工作。当我断开Internet连接时,我没有从所有消息中收到NotConnectedError(EAI_AGAIN)。

我做了以下代码,每1分钟发送一条消息以演示该问题:

var Protocol = require('azure-iot-device-mqtt').Mqtt;
var Client = require('azure-iot-device').Client;
var Message = require('azure-iot-device').Message;

...

var sendInterval = setInterval(function () {
      counter++;
      var data = JSON.stringify({ deviceId: 'myFirstDevice', temperature: temperature, count: counter });
      var message = new Message(data);
      console.log('Sending message: ' + message.getData() + " at:" + new Date());
      client.sendEvent(message, printResultFor(message));
    }, 60000);

function printResultFor(op) {
  return function printResult(err, res) {
    if (err) {console.error('Send error: ' + new Date() + " " + op.getData()); console.log(op + ' error: ' + err.toString());}
    else if (res) console.log(op + ' Send status: ' + res.constructor.name);
    else console.log(op + ' status: == completed ');
  };
}

日志:

 Client connected
    Sending message: {"deviceId":"myFirstDevice","temperature":20,"count":1} at:Tue Aug 27 2019 14:59:02 GMT-0300 (-03)
    [object Object] Send status: MessageEnqueued
    **----->> Here i disconnected from Internet**
    Sending message: {"deviceId":"myFirstDevice","temperature":20,"count":2} at:Tue Aug 27 2019 15:00:02 GMT-0300 (-03)
    Sending message: {"deviceId":"myFirstDevice","temperature":20,"count":3} at:Tue Aug 27 2019 15:01:02 GMT-0300 (-03)
    Sending message: {"deviceId":"myFirstDevice","temperature":20,"count":4} at:Tue Aug 27 2019 15:02:02 GMT-0300 (-03)
    Sending message: {"deviceId":"myFirstDevice","temperature":20,"count":5} at:Tue Aug 27 2019 15:03:02 GMT-0300 (-03)
    Sending message: {"deviceId":"myFirstDevice","temperature":20,"count":6} at:Tue Aug 27 2019 15:04:03 GMT-0300 (-03)
    Sending message: {"deviceId":"myFirstDevice","temperature":20,"count":7} at:Tue Aug 27 2019 15:05:03 GMT-0300 (-03)
    Sending message: {"deviceId":"myFirstDevice","temperature":20,"count":8} at:Tue Aug 27 2019 15:06:03 GMT-0300 (-03)
    Sending message: {"deviceId":"myFirstDevice","temperature":20,"count":9} at:Tue Aug 27 2019 15:07:03 GMT-0300 (-03)
    Sending message: {"deviceId":"myFirstDevice","temperature":20,"count":10} at:Tue Aug 27 2019 15:08:03 GMT-0300 (-03)
    Send error: Tue Aug 27 2019 15:08:59 GMT-0300 (-03) {"deviceId":"myFirstDevice","temperature":20,"count":7}
    [object Object] error: NotConnectedError: getaddrinfo EAI_AGAIN iot-hub-teste.azure-devices.net:8883
    Send error: Tue Aug 27 2019 15:09:58 GMT-0300 (-03) {"deviceId":"myFirstDevice","temperature":20,"count":8}
    [object Object] error: NotConnectedError: getaddrinfo EAI_AGAIN iot-hub-teste.azure-devices.net:8883
    Send error: Tue Aug 27 2019 15:10:59 GMT-0300 (-03) {"deviceId":"myFirstDevice","temperature":20,"count":9}
    [object Object] error: NotConnectedError: getaddrinfo EAI_AGAIN iot-hub-teste.azure-devices.net:8883
    Send error: Tue Aug 27 2019 15:11:54 GMT-0300 (-03) {"deviceId":"myFirstDevice","temperature":20,"count":10}
    [object Object] error: NotConnectedError: getaddrinfo EAI_AGAIN iot-hub-teste.azure-devices.net:8883

期望接收到所有消息的NotConnectedError,但是在此示例中,我仅从最近的4条消息中接收到。消息2至6会发生什么?

最诚挚的问候

0 个答案:

没有答案