Skip to content

Instantly share code, notes, and snippets.

@alepez
Last active April 10, 2017 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alepez/2d0621f31677f37f7752d1bc2a2681b5 to your computer and use it in GitHub Desktop.
Save alepez/2d0621f31677f37f7752d1bc2a2681b5 to your computer and use it in GitHub Desktop.
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