From c1f17a7d99fb37fb1ca229379d249965efcdad4e Mon Sep 17 00:00:00 2001 From: Nicolas Dextraze Date: Sun, 21 Oct 2018 14:46:55 -0700 Subject: [PATCH] #61 fixed subscriptionDropped being called only once Added subscribe-all-from-events sample to test --- samples/subscribe-all-from-events.js | 50 ++++++++++++++++++++++++++++ src/eventStoreCatchUpSubscription.js | 2 ++ 2 files changed, 52 insertions(+) create mode 100644 samples/subscribe-all-from-events.js diff --git a/samples/subscribe-all-from-events.js b/samples/subscribe-all-from-events.js new file mode 100644 index 0000000..3b772a8 --- /dev/null +++ b/samples/subscribe-all-from-events.js @@ -0,0 +1,50 @@ +const client = require('../src/client'); +//const client = require("node-eventstore-client"); + +const resolveLinkTos = true; + +function resumeEvent(event) { + return [ + event.originalEvent.eventType, + [event.originalEventNumber.toNumber(), event.originalStreamId].join('@'), + event.originalPosition + ].join(" ") +} + +const eventAppeared = (subscription, event) => console.log("Event received", resumeEvent(event)); + +const subscriptionDropped = (subscription, reason, error) => console.log("Subscription dropped", reason, error); + +const libeProcessingStarted = () => console.log("Live processing started."); + +const credentials = new client.UserCredentials("admin", "changeit"); + +const settings = {}; +const endpoint = "tcp://localhost:1113"; +const connection = client.createConnection(settings, endpoint); + +connection.connect().catch(err => console.log("Connection failed", err)); + +connection.on('heartbeatInfo', heartbeatInfo => + console.log('Heartbeat latency', heartbeatInfo.responseReceivedAt - heartbeatInfo.requestSentAt, 'ms') +); + +connection.once("connected", tcpEndPoint => { + console.log(`Connected to eventstore at ${tcpEndPoint.host}:${tcpEndPoint.port}`); + connection.subscribeToAllFrom( + null, + resolveLinkTos, + eventAppeared, + libeProcessingStarted, + subscriptionDropped, + credentials + ); +}); + +connection.on("error", error => + console.log(`Error occurred on connection: ${error}`) +) + +connection.on("closed", reason => + console.log(`Connection closed, reason: ${reason}`) +) diff --git a/src/eventStoreCatchUpSubscription.js b/src/eventStoreCatchUpSubscription.js index 4950351..41a6d2a 100644 --- a/src/eventStoreCatchUpSubscription.js +++ b/src/eventStoreCatchUpSubscription.js @@ -127,6 +127,8 @@ EventStoreCatchUpSubscription.prototype._runSubscription = function() { var self = this; this._stopped = false; + this._isDropped = false; + this._dropData = null; if (this._verbose) this._log.debug("Catch-up Subscription to %s: pulling events...", logStreamName); this._readEventsTill(this._connection, this._resolveLinkTos, this._userCredentials, null, null) .then(function() {