Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 168 lines (108 sloc) 5.056 kb
4ad6abb7 »
2012-01-06 first draft
1 # Introduction
aee628ad »
2011-09-01 initial commit
2
97bd54b8 »
2012-01-26 Update README.markdown
3 [![Build Status](https://secure.travis-ci.org/KABA-CCEAC/nodeEventStore.png)](http://travis-ci.org/KABA-CCEAC/nodeEventStore)
189be6a8 »
2012-01-26 Update README.markdown
4
4ad6abb7 »
2012-01-06 first draft
5 The project goal is to provide an eventstore implementation for node.js:
aee628ad »
2011-09-01 initial commit
6
4ad6abb7 »
2012-01-06 first draft
7 - load and store events via EventStream object
8 - event dispatching to your publisher
4c17a02b » Adriano Raiano
2012-04-27 update to node 0.6.15
9 - supported Dbs (MongoDb, Redis)
4ad6abb7 »
2012-01-06 first draft
10 - snapshot support
aee628ad »
2011-09-01 initial commit
11
4ad6abb7 »
2012-01-06 first draft
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 redis
22 npm install eventstore.redis
23
24 # Usage
25
26 ### Require the module and init the eventstore:
27
28 var eventstore = require('eventstore');
29
30 var es = eventstore.createStore(); // optional pass in your options
a86da9ae » Adriano Raiano
2013-01-07 make forking of eventdispatching configurable
31 // to disable forking of event dispatching set forkDispatching to false
4ad6abb7 »
2012-01-06 first draft
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
4c17a02b » Adriano Raiano
2012-04-27 update to node 0.6.15
40 Example will use redis storage, but same will work for mongoDb.
4ad6abb7 »
2012-01-06 first draft
41
0b3f3363 » mathiasverraes
2012-10-23 fixed incorrect require statement
42 var storage = require('eventstore.redis');
4ad6abb7 »
2012-01-06 first draft
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
b43b97de » Adriano Raiano
2012-10-01 added doc for replaying events
109 ### Replaying events
4ad6abb7 »
2012-01-06 first draft
110
b43b97de » Adriano Raiano
2012-10-01 added doc for replaying events
111 If you want to replay all events from the store you can do it with the function getEventRange:
112
113 var match = {} // match query in inner event (payload), for example: { id: eventId }
114 // if {} all events will return
115 , amount = 20; // amount of events to receive per request
116
117 var handle = function(err, events) {
118 // events is the eventstream
119 if (events.length === amount) {
120 events.next(handle);
121 } else {
122 // finished to replay
123 }
124 };
125
126 es.getEventRange(match, amount, handle);
127
128
129 If you want to replay all events of a particular aggregate or stream you can do it with the function getEvents:
130
131 var streamId = '1234'
132 , revMin = null // optional, must be a number
133 , revMax = null; // optional, must be a number
134
135 es.getEvents(streamId, revMin, revMax, function(err, events) {
136 // events is the eventstream
137 });
4ad6abb7 »
2012-01-06 first draft
138
139
140 # Sample Integration
141
142 - [nodeCQRS](https://github.com/jamuhl/nodeCQRS) A CQRS sample integrating eventstore
143
144 # Inspiration
145
146 - Jonathan Oliver's [EventStore](https://github.com/joliver/EventStore) for .net.
147
148 # License
149
4c17a02b » Adriano Raiano
2012-04-27 update to node 0.6.15
150 Copyright (c) 2012 Jan Muehlemann, Adriano Raiano
4ad6abb7 »
2012-01-06 first draft
151
152 Permission is hereby granted, free of charge, to any person obtaining a copy
153 of this software and associated documentation files (the "Software"), to deal
154 in the Software without restriction, including without limitation the rights
155 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
156 copies of the Software, and to permit persons to whom the Software is
157 furnished to do so, subject to the following conditions:
158
159 The above copyright notice and this permission notice shall be included in
160 all copies or substantial portions of the Software.
161
162 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
163 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
164 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
165 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
166 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
167 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
168 THE SOFTWARE.
aee628ad »
2011-09-01 initial commit
169
170
Something went wrong with that request. Please try again.