BlueCastle
BlueCastle

Reputation: 217

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

I am using azure-iot-device-http, and runnint the getting started code:

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);
  });
});

But I am receiving this error:

TypeError: client.getReceiver is not a function

Upvotes: 1

Views: 396

Answers (1)

bolav
bolav

Reputation: 6998

It seems like this is an error in the libraries examples. It doesn't look like it defines client.getReceiver. You should probably commit a bug here: github issues.

Try to use

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

as a workaround for

client.getReceiver(function (err, rcv) {

until they fix it in the library.

Upvotes: 1

Related Questions