Last active
August 29, 2015 14:23
-
-
Save bmavity/e4f4031a569de04c1ef5 to your computer and use it in GitHub Desktop.
Event Store Subscription
This file contains 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
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