Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 140 lines (87 sloc) 4.017 kb
4ad6abb7 »
2012-01-06 first draft
1 # Introduction
aee628ad »
2011-09-01 initial commit
2
4ad6abb7 »
2012-01-06 first draft
3 The project goal is to provide an eventstore implementation for node.js:
aee628ad »
2011-09-01 initial commit
4
4ad6abb7 »
2012-01-06 first draft
5 - load and store events via EventStream object
6 - event dispatching to your publisher
7 - supported Dbs (MongoDb, CouchDb, Redis)
8 - snapshot support
aee628ad »
2011-09-01 initial commit
9
4ad6abb7 »
2012-01-06 first draft
10 # Installation
11
12 npm install eventstore
13
14 choose one of the existing storage implementation or provide your own:
15
16 // for mongoDb
17 npm install eventstore.mongoDb
18
19 // for couchDb
20 npm install eventstore.couchDb
21
22 // for redis
23 npm install eventstore.redis
24
25 # Usage
26
27 ### Require the module and init the eventstore:
28
29 var eventstore = require('eventstore');
30
31 var es = eventstore.createStore(); // optional pass in your options
32
33 By default the eventstore will use an inMemory Storage, a fakePublisher and no logger.
34
35 To use the provided console.logger you could create the eventstore
36 with option `eventstore.createStore({logger: 'console'});`.
37
38 ### Provide implementation for storage and publishing events
39
40 Example will use redis storage, but same will work for mongoDb and couchDb.
41
42 require storage = require('eventstore.redis');
43
44 storage.createStorage(function(err, store) {
45 es.configure(function() {
46 es.use(store);
47 es.use(publisher); // your publisher must provide function 'publisher.publish(event)'
48 // es.use(logger);
49 });
50
51 // start eventstore
52 es.start();
53 });
54
55 ### Work with the eventstore
56
57 get the eventhistory of an aggregate
58
59 es.getEventStream(aggregateId, 0, function(err, stream) {
60 var history = stream.events; // the original event will be in events[i].payload
61
62 // myAggregate.loadFromHistory(history);
63 });
64
65 store a new event and commit it to store
66
67 es.getEventStream(aggregateId, 0, function(err, stream) {
68
69 stream.addEvent(new event);
70 stream.commit();
71
72 });
73
74 the committed event will be dispatched to the provided publisher
75
76 ### Work with snapshotting
77
78 get snapshot and eventhistory from the snapshot point
79
80 es.getFromSnapshot(aggregateId, function(err, snapshot, stream) {
81
82 var snap = snapshot.data;
83 var history = stream.events; // events history from given snapshot
84
85 myAggregate.loadSnapshot(snap);
86 myAggregate.loadFromHistory(history);
87
88 });
89
90 create a snapshot point
91
92 es.getFromSnapshot(aggregateId, function(err, snapshot, stream) {
93
94 var snap = snapshot.data;
95 var history = stream.events; // events history from given snapshot
96
97 myAggregate.loadSnapshot(snap);
98 myAggregate.loadFromHistory(history);
99
100 // create a new snapshot depending on your rules
101 if (history.length > myRange) {
102 es.createSnapshot(aggregateId, stream.currentRevision(), myAggregate.getSnap());
103 }
104
105 // go on: store new event and commit it
106
107 });
108
109
110
111
112 # Sample Integration
113
114 - [nodeCQRS](https://github.com/jamuhl/nodeCQRS) A CQRS sample integrating eventstore
115
116 # Inspiration
117
118 - Jonathan Oliver's [EventStore](https://github.com/joliver/EventStore) for .net.
119
120 # License
121
122 Copyright (c) 2012 Kaba AG, MIC AWM
123
124 Permission is hereby granted, free of charge, to any person obtaining a copy
125 of this software and associated documentation files (the "Software"), to deal
126 in the Software without restriction, including without limitation the rights
127 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
128 copies of the Software, and to permit persons to whom the Software is
129 furnished to do so, subject to the following conditions:
130
131 The above copyright notice and this permission notice shall be included in
132 all copies or substantial portions of the Software.
133
134 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
135 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
136 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
137 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
138 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
139 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
140 THE SOFTWARE.
aee628ad »
2011-09-01 initial commit
141
142
Something went wrong with that request. Please try again.