Last active
April 10, 2017 13:56
-
-
Save alepez/2d0621f31677f37f7752d1bc2a2681b5 to your computer and use it in GitHub Desktop.
EventHub Receiver
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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