diff --git a/package.json b/package.json index d93cf4a..aa4693c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eventstore-node", - "version": "0.0.6", + "version": "0.0.7", "description": "A port of the EventStore .Net ClientAPI to Node.js", "main": "index.js", "scripts": { diff --git a/samples/simple.js b/samples/simple.js new file mode 100644 index 0000000..6f9f8fe --- /dev/null +++ b/samples/simple.js @@ -0,0 +1,39 @@ +var client = require('../src/client'); +var uuid = require('uuid'); + +var settings = { + verboseLogging: true, + log: new client.FileLogger('./simple-verbose.log') +}; +var gossipSeeds = [ + new client.GossipSeed({hostname: 'localhost', port: 1113}), + new client.GossipSeed({hostname: 'localhost', port: 2113}), + new client.GossipSeed({hostname: 'localhost', port: 3113}) + ]; +var conn = client.createConnection(settings, gossipSeeds); +conn.connect() + .catch(function (err) { + console.log(err); + //process.exit(-1); + }); +conn.on('connected', function (endPoint) { + console.log('connected to endPoint', endPoint); + //Start some work + setInterval(function () { + conn.appendToStream('test-' + uuid.v4(), client.expectedVersion.noStream, [ + client.createJsonEventData(uuid.v4(), {abc: 123}, null, 'MyEvent') + ]).then(function (writeResult) { + console.log(writeResult); + }); + }, 1000); +}); +conn.on('error', function (err) { + console.log('Error occurred on connection:', err); +}); +conn.on('closed', function (reason) { + console.log('Connection closed, reason:', reason); + //process.exit(-1); +}); +process.stdin.setRawMode(true); +process.stdin.resume(); +process.stdin.on('data', process.exit.bind(process, 0)); \ No newline at end of file diff --git a/src/client.js b/src/client.js index 8bef120..e6a4762 100644 --- a/src/client.js +++ b/src/client.js @@ -38,24 +38,27 @@ function eventDataFactory(eventId, type, isJson, data, metadata) { return new EventData(eventId, type, isJson, data, metadata); } -// Exporting classes +// Expose classes module.exports.EventStoreConnection = require('./eventStoreConnection'); module.exports.UserCredentials = require('./systemData/userCredentials'); module.exports.EventData = EventData; module.exports.PersistentSubscriptionSettings = require('./persistentSubscriptionSettings'); module.exports.SystemConsumerStrategies = require('./systemConsumerStrategies'); module.exports.GossipSeed = require('./gossipSeed'); -// Exporting errors +// Expose errors module.exports.WrongExpectedVersionError = require('./errors/wrongExpectedVersionError'); module.exports.StreamDeletedError = require('./errors/streamDeletedError'); module.exports.AccessDeniedError = require('./errors/accessDeniedError'); -// Exporting enums/constants +// Expose enums/constants module.exports.expectedVersion = expectedVersion; module.exports.positions = positions; module.exports.systemMetadata = require('./common/systemMetadata'); module.exports.eventReadStatus = results.EventReadStatus; module.exports.sliceReadStatus = require('./sliceReadStatus'); -// Helper functions +// Expose loggers +module.exports.NoopLogger = require('./common/log/noopLogger'); +module.exports.FileLogger = require('./common/log/fileLogger'); +// Expose Helper functions module.exports.createConnection = module.exports.EventStoreConnection.create; module.exports.createEventData = eventDataFactory; module.exports.createJsonEventData = jsonEventDataFactory; \ No newline at end of file diff --git a/src/common/log/fileLogger.js b/src/common/log/fileLogger.js index 4e2486c..8d19e22 100644 --- a/src/common/log/fileLogger.js +++ b/src/common/log/fileLogger.js @@ -6,7 +6,7 @@ function FileLogger(filePath, append) { this._filePath = filePath; if (!append) { try { - fs.unlink(filePath); + fs.unlinkSync(filePath); } catch(e) {} } } diff --git a/src/core/simpleQueuedHandler.js b/src/core/simpleQueuedHandler.js index d6dbe8d..607cef8 100644 --- a/src/core/simpleQueuedHandler.js +++ b/src/core/simpleQueuedHandler.js @@ -18,7 +18,7 @@ SimpleQueuedHandler.prototype.registerHandler = function(type, handler) { try { handler(msg); } catch(e) { - console.log('ERROR: ', e); + console.log('ERROR: ', e.stack); } }; }; diff --git a/test/common/base_test.js b/test/common/base_test.js index 319ef37..8234c2d 100644 --- a/test/common/base_test.js +++ b/test/common/base_test.js @@ -34,7 +34,8 @@ function setUp(cb) { settings.log.error(error, "Connection to %j failed.", tcpEndPoint); cb(error); }); - this.conn.on('connected', function () { + this.conn.on('connected', function (tcpEndPoint) { + if (connected) return; settings.log.debug("Connected to %j.", tcpEndPoint); connected = true; cb();