Thursday, 20 April 2017

EventHubClient open function call gives Bad Request Error on cloud nodejs web app

I have tried ReadDeviceToCloudMessages.js example with a node js web app on cloud. When I started it on console it gave bad request error. When I tried exactly same example on my pc and started it, it worked completely fine. Shouldn't EventHubClient run on cloud at app Back end? What am I doing wrong?

    'use strict';

var EventHubClient = require('azure-event-hubs').Client;

var connectionString = 'HostName=TestHubNil.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=WCk993BaIrVGjFdIL5IU6asEK0HXIMBGVUdZU+a4T90=';



var printError = function (err)
{
    console.log(err.message);
};

var printMessage = function (message)
{
    console.log('Message received: ');
    console.log(JSON.stringify(message.body));
    console.log('');
};


var client = EventHubClient.fromConnectionString(connectionString);

client.open()
    .then(client.getPartitionIds.bind(client))
    .then(function (partitionIds)
    {
        return partitionIds.map(function (partitionId)
        {
            return client.createReceiver('$Default', partitionId, { 'startAfterTime': Date.now() }).then(function (receiver)
            {
                console.log('Created partition receiver: ' + partitionId)
                receiver.on('errorReceived', printError);
                receiver.on('message', printMessage);
            });
        });
    })
    .catch(printError);



via user3127584

No comments:

Post a Comment