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