You don't need to call connect...
instead of calling:
store.connect(function(){cb(null);})
i would call:
es.start(function(){cb(null);})
and not calling es.start after configuration.
Pergunta
I am new to event source, and I am using nodeEventStore.
So I wrote the following simple test console application, and I found that the event will be published twice, could anyone help me to figure out why? thanks.
var eventstore = require('eventstore');
var storage = require('eventstore.mongoDb');
var async = require('async');
publisher = {
publish: function(evt) {
console.log('publishing: ');
console.log(evt);
}
}
var es = eventstore.createStore();
var store = storage.createStorage({
host: 'localhost',
port: 27017,
db: 'es'
});
es.configure(function() {
es.use(store);
es.use(publisher);
}).start();
async.series([
function(cb) {store.connect(function(){cb(null);})},
function(cb) {
es.getEventStream('1', 0, function(err, stream) {
stream.addEvent({id: '1', event:'add', payload:{}});
stream.commit();
cb(null);
});
}
]);
and the output of the above is twice which is not expected:
publishing:
{ id: '1', event: 'add', payload: {} }
publishing:
{ id: '1', event: 'add', payload: {} }
By the way, if I connect within createStorage below, it works just fine:
var eventstore = require('eventstore');
var storage = require('eventstore.mongoDb');
var async = require('async');
publisher = {
publish: function(evt) {
console.log('publishing: ');
console.log(evt);
}
}
var es = eventstore.createStore();
async.series([
function(cb) {
storage.createStorage({
host: 'localhost',
port: 27017,
dbName: 'es'
}, function(err, store) {
es.configure(function() {
es.use(store);
es.use(publisher);
});
es.start();
cb(null);
});
},
function(cb) {
es.getEventStream('1', 0, function(err, stream) {
stream.addEvent({id: '1', event:'add', payload:{}});
stream.commit();
cb(null);
});
}
]);
Solução
You don't need to call connect...
instead of calling:
store.connect(function(){cb(null);})
i would call:
es.start(function(){cb(null);})
and not calling es.start after configuration.