TypeError: client.getReceiver is not a function in azure-iot-device-http examples

TypeError: client.getReceiver is not a function in azure-iot-device-http examples

我正在使用 azure-iot-device-http,并运行入门代码:

var clientFromConnectionString = require('azure-iot-device-http').clientFromConnectionString;
var Message = require('azure-iot-device').Message;
var connectionString = 'myHostname,myDevice,myKey;
var client = clientFromConnectionString(connectionString);
var msg = new Message('some data from my device');

client.sendEvent(msg, function (err) {
  if (err) console.log(err.toString());
});

client.getReceiver(function (err, rcv) {
  rcv.on('message', function (msg) {
    console.log(msg);
    rcv.complete(msg, function () {
      console.log('completed');
    });
  });
  rcv.on('errorReceived', function (err) {
    console.warn(err);
  });
});

但是我收到这个错误:

TypeError: client.getReceiver is not a function

这似乎是库示例中的一个错误。它看起来不像是定义 client.getReceiver。您可能应该在这里提交错误:github issues.

尝试使用

client._transport.getReceiver(function (err, rcv) {

作为

的解决方法
client.getReceiver(function (err, rcv) {

直到他们在图书馆修复它。