Skip to content

Instantly share code, notes, and snippets.

@bmavity
Last active August 29, 2015 14:23
Show Gist options
  • Save bmavity/e4f4031a569de04c1ef5 to your computer and use it in GitHub Desktop.
Save bmavity/e4f4031a569de04c1ef5 to your computer and use it in GitHub Desktop.
Event Store Subscription
var ges = require('ges-client')
, connection = ges()
, shouldSetMetadata = false
connection.on('connect', function() {
function setMetadata(done) {
var setData = {
expectedMetastreamVersion: ges.expectedVersion.emptyStream
, metadata: ges.createStreamMetadata({
acl: {
readRoles: ges.systemRoles.all
}
})
, auth: {
username: ges.systemUsers.admin
, password: ges.systemUsers.defaultAdminPassword
}
}
connection.setStreamMetadata('$all', setData, done)
}
if(shouldSetMetadata) {
setMetadata(runSubscription)
} else {
runSubscription()
}
function runSubscription() {
var subscription = connection.subscribeToAllFrom()
subscription.on('event', function(evt) {
console.log(evt)
})
subscription.on('dropped', function() {
console.log('dropped')
})
subscription.on('error', function(err) {
console.log(err)
})
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment