Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
EventHub Receiver
const EventHubClient = require('azure-event-hubs').Client;
const Promise = require('bluebird');
const connectionString = '__OBFUSCATED__';
const eventHubPath = 'foo';
const client = EventHubClient.fromConnectionString(connectionString, eventHubPath);
var printError = function(err) {
console.error(err.message);
};
var receiveAfterTime = Date.now();
console.log('Connecting...');
client.open()
.then(function() {
console.log('Client connected');
return client.getPartitionIds();
})
.then(function(partitionIds) {
return Promise.map(partitionIds, function(partitionId) {
return client.createReceiver('$Default', partitionId, {
'startAfterTime': receiveAfterTime
}).then(function(receiver) {
receiver.on('errorReceived', printError);
receiver.on('message', function(event) {
console.log(`partitionId: ${partitionId}, partitionKey: ${event.partitionKey}`);
});
});
});
})
.catch(printError);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment