rails_event_store 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/CONTRIBUTING.md +27 -0
- data/README.md +4 -197
- data/lib/rails_event_store/client.rb +12 -0
- data/lib/rails_event_store/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69cc1d3ee940054aa247a3effcbc4590a9c87305
|
4
|
+
data.tar.gz: 40e656548799d5bcf0c1921bbf914d75d07d389f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0637153e87843e2e23cc1705b5e09a2dd997af2116419c5ae4990ce1c5e04bbc95dd4e98a5afbb95756a57cabf43e8ac686861fed714d4e492b5817791e549a7
|
7
|
+
data.tar.gz: f4741353b9109b2a981c24d900d5e32f2f34ce8d2817265b1577c7bdf7c5be7fb6f937f9e971433664c9c832eb2ed6c09533e9369471e23a3c0c709d604ce1a2
|
data/CHANGELOG.md
CHANGED
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# Contributing to RailsEventStore
|
2
|
+
|
3
|
+
Any kind of contribution is welcomed. Here is a few guidelines that we need contributors to follow.
|
4
|
+
|
5
|
+
## Found a bug? Have a question?
|
6
|
+
|
7
|
+
* [Create a new issue](https://github.com/arkency/rails_event_store/issues/new), assuming one does not already exist.
|
8
|
+
* Clearly describe the issue including steps to reproduce when it is a bug.
|
9
|
+
* If possible provide a Pull Request with failing test case.
|
10
|
+
|
11
|
+
## Getting Started
|
12
|
+
|
13
|
+
* Make sure you have a [GitHub account](https://github.com/signup/free).
|
14
|
+
* [Fork the repository](https://help.github.com/articles/fork-a-repo/) on GitHub.
|
15
|
+
|
16
|
+
## Making Changes
|
17
|
+
|
18
|
+
* Create a feature branch from where you want to base your work.
|
19
|
+
* Do your work. Please try to keep your commits small and focussed.
|
20
|
+
* Make sure you have added the necessary tests for your changes.
|
21
|
+
* Push your changes to a feature branch in your fork of the repository.
|
22
|
+
* Submit a pull request to the RailsEventStore repository.
|
23
|
+
|
24
|
+
# Additional Resources
|
25
|
+
|
26
|
+
* [General GitHub documentation](http://help.github.com/)
|
27
|
+
* [GitHub pull request documentation](http://help.github.com/send-pull-requests/)
|
data/README.md
CHANGED
@@ -9,206 +9,13 @@
|
|
9
9
|
A Ruby implementation of an EventStore.
|
10
10
|
Default storage is events repository based on Active Record (provided by separate gem: [rails_event_store_active_record](http://github.com/arkency/rails_event_store_active_record)).
|
11
11
|
|
12
|
-
|
12
|
+
# Documentation
|
13
13
|
|
14
|
-
|
14
|
+
All documentation and sample codes are available at [http://railseventstore.arkency.com](http://railseventstore.arkency.com)
|
15
15
|
|
16
|
-
|
17
|
-
gem 'rails_event_store'
|
18
|
-
```
|
16
|
+
# Contributing
|
19
17
|
|
20
|
-
|
21
|
-
|
22
|
-
```ruby
|
23
|
-
rails generate rails_event_store_active_record:migration
|
24
|
-
rake db:migrate
|
25
|
-
```
|
26
|
-
|
27
|
-
## Usage
|
28
|
-
|
29
|
-
To communicate with ES you have to create instance of `RailsEventStore::Client` class.
|
30
|
-
|
31
|
-
```ruby
|
32
|
-
client = RailsEventStore::Client.new
|
33
|
-
```
|
34
|
-
|
35
|
-
#### Creating new event
|
36
|
-
|
37
|
-
Firstly you have to define own event model extending `RailsEventStore::Event` class.
|
38
|
-
|
39
|
-
```ruby
|
40
|
-
class OrderCreated < RailsEventStore::Event
|
41
|
-
end
|
42
|
-
|
43
|
-
# or
|
44
|
-
|
45
|
-
OrderCreated = Class.new(RailsEventStore::Event)
|
46
|
-
```
|
47
|
-
|
48
|
-
```ruby
|
49
|
-
stream_name = "order_1"
|
50
|
-
event = OrderCreated.new(
|
51
|
-
data: "sample",
|
52
|
-
event_id: "b2d506fd-409d-4ec7-b02f-c6d2295c7edd"
|
53
|
-
)
|
54
|
-
#publishing event for specific stream
|
55
|
-
client.publish_event(event, stream_name)
|
56
|
-
|
57
|
-
#publishing global event. In this case stream_name is 'all'.
|
58
|
-
client.publish_event(event)
|
59
|
-
```
|
60
|
-
|
61
|
-
#### Creating new event with optimistic locking:
|
62
|
-
|
63
|
-
```ruby
|
64
|
-
class OrderCreated < RailsEventStore::Event
|
65
|
-
end
|
66
|
-
```
|
67
|
-
|
68
|
-
```ruby
|
69
|
-
stream_name = "order_1"
|
70
|
-
event = OrderCreated.new(
|
71
|
-
data: "sample",
|
72
|
-
event_id: "b2d506fd-409d-4ec7-b02f-c6d2295c7edd"
|
73
|
-
)
|
74
|
-
expected_version = "850c347f-423a-4158-a5ce-b885396c5b73" #last event_id
|
75
|
-
client.publish_event(event, stream_name, expected_version)
|
76
|
-
```
|
77
|
-
|
78
|
-
#### Reading stream's events forward in batch - starting from first event
|
79
|
-
|
80
|
-
```ruby
|
81
|
-
stream_name = "order_1"
|
82
|
-
count = 40
|
83
|
-
client.read_events_forward(stream_name, :head, count)
|
84
|
-
```
|
85
|
-
|
86
|
-
In this case `:head` means first event of the stream.
|
87
|
-
|
88
|
-
#### Reading stream's events forward in batch - staring from given event
|
89
|
-
|
90
|
-
```ruby
|
91
|
-
# last_read_event is any domain event read or published by rails_event_store
|
92
|
-
|
93
|
-
stream_name = "order_1"
|
94
|
-
start = last_read_event.event_id
|
95
|
-
count = 40
|
96
|
-
client.read_events_forward(stream_name, start, count)
|
97
|
-
```
|
98
|
-
|
99
|
-
#### Reading stream's events backward in batch
|
100
|
-
|
101
|
-
As in examples above, just use `read_events_backward` instead of `read_events_forward`.
|
102
|
-
In this case `:head` means last event of the stream.
|
103
|
-
|
104
|
-
#### Reading all events from stream forward
|
105
|
-
|
106
|
-
This method allows us to load all stream's events ascending.
|
107
|
-
|
108
|
-
```ruby
|
109
|
-
stream_name = "order_1"
|
110
|
-
client.read_stream_events_forward(stream_name)
|
111
|
-
```
|
112
|
-
|
113
|
-
#### Reading all events from stream forward
|
114
|
-
|
115
|
-
This method allows us to load all stream's events descending.
|
116
|
-
|
117
|
-
```ruby
|
118
|
-
stream_name = "order_1"
|
119
|
-
client.read_stream_events_backward(stream_name)
|
120
|
-
```
|
121
|
-
|
122
|
-
#### Reading all events forward
|
123
|
-
|
124
|
-
This method allows us to load all stored events ascending.
|
125
|
-
|
126
|
-
This will read first 100 domain events stored in event store.
|
127
|
-
|
128
|
-
```ruby
|
129
|
-
client.read_all_streams_forward(:head, 100)
|
130
|
-
```
|
131
|
-
|
132
|
-
When not specified it reads events starting from `:head` (first domain event
|
133
|
-
stored in event store) and reads up to `RailsEventStore::PAGE_SIZE`
|
134
|
-
domain events.
|
135
|
-
|
136
|
-
```ruby
|
137
|
-
client.read_all_streams_forward
|
138
|
-
```
|
139
|
-
|
140
|
-
You could also read batch of domain events starting from any read or published event.
|
141
|
-
|
142
|
-
```ruby
|
143
|
-
client.read_all_streams_forward(last_read_event.event_id, 100)
|
144
|
-
```
|
145
|
-
|
146
|
-
#### Reading all events backward
|
147
|
-
|
148
|
-
This method allows us to load all stored events descending.
|
149
|
-
|
150
|
-
This will read last 100 domain events stored in event store.
|
151
|
-
```ruby
|
152
|
-
client.read_all_streams_backward(:head, 100)
|
153
|
-
```
|
154
|
-
|
155
|
-
When not specified it reads events starting from `:head` (last domain event
|
156
|
-
stored in event store) and reads up to `RailsEventStore::PAGE_SIZE`
|
157
|
-
domain events.
|
158
|
-
|
159
|
-
```ruby
|
160
|
-
client.read_all_streams_backward
|
161
|
-
```
|
162
|
-
|
163
|
-
#### Deleting stream
|
164
|
-
|
165
|
-
You can permanently delete all events from a specific stream. Use this wisely.
|
166
|
-
|
167
|
-
```ruby
|
168
|
-
stream_name = "product_1"
|
169
|
-
client.delete_stream(stream_name)
|
170
|
-
```
|
171
|
-
|
172
|
-
#### Subscribing to events
|
173
|
-
|
174
|
-
To listen on specific events synchronously you have to create subscriber representation. The only requirement is that subscriber class has to implement the 'handle_event(event)' method.
|
175
|
-
|
176
|
-
```ruby
|
177
|
-
class InvoiceReadModel
|
178
|
-
def handle_event(event)
|
179
|
-
#we deal here with event's data
|
180
|
-
end
|
181
|
-
end
|
182
|
-
```
|
183
|
-
|
184
|
-
* You can subscribe on specific set of events
|
185
|
-
|
186
|
-
```ruby
|
187
|
-
invoice = InvoiceReadModel.new
|
188
|
-
client.subscribe(invoice, [PriceChanged, ProductAdded])
|
189
|
-
```
|
190
|
-
|
191
|
-
* You can also listen on all incoming events
|
192
|
-
|
193
|
-
```ruby
|
194
|
-
invoice = InvoiceReadModel.new
|
195
|
-
client.subscribe_to_all_events(invoice)
|
196
|
-
```
|
197
|
-
|
198
|
-
#### Building an event sourced application with RailsEventStore gem
|
199
|
-
|
200
|
-
ArrgegateRoot module & AggregateReporitory have been extracted from RailsEventStore to separate gem.
|
201
|
-
See [aggregate_root](https://github.com/arkency/aggregate_root) gem readme to find help how to start.
|
202
|
-
Also [this example](https://github.com/mpraglowski/cqrs-es-sample-with-res) might be useful.
|
203
|
-
|
204
|
-
#### Resources
|
205
|
-
|
206
|
-
There're already few blogposts about Rails EventStore. Check them out:
|
207
|
-
|
208
|
-
* [Why use Event Sourcing](http://blog.arkency.com/2015/03/why-use-event-sourcing/)
|
209
|
-
* [The Event Store for Rails developers](http://blog.arkency.com/2015/04/the-event-store-for-rails-developers/)
|
210
|
-
* [Fast introduction to Event Sourcing for Ruby programmers](http://blog.arkency.com/2015/03/fast-introduction-to-event-sourcing-for-ruby-programmers/)
|
211
|
-
* [Why I want to introduce mutation testing to the rails_event_store gem](http://blog.arkency.com/2015/04/why-i-want-to-introduce-mutation-testing-to-the-rails-event-store-gem/)
|
18
|
+
Check the contribution guide on [CONTRIBUTING.md](https://github.com/arkency/rails_event_store/blob/master/CONTRIBUTING.md)
|
212
19
|
|
213
20
|
## About
|
214
21
|
|
@@ -26,16 +26,28 @@ module RailsEventStore
|
|
26
26
|
end
|
27
27
|
alias :read_events :read_events_forward
|
28
28
|
|
29
|
+
def read_events_backward(stream_name, start = :head, count = page_size)
|
30
|
+
event_store.read_events_backward(stream_name, start, count)
|
31
|
+
end
|
32
|
+
|
29
33
|
def read_stream_events_forward(stream_name)
|
30
34
|
event_store.read_stream_events_forward(stream_name)
|
31
35
|
end
|
32
36
|
alias :read_all_events :read_stream_events_forward
|
33
37
|
|
38
|
+
def read_stream_events_backward(stream_name)
|
39
|
+
event_store.read_stream_events_backward(stream_name)
|
40
|
+
end
|
41
|
+
|
34
42
|
def read_all_streams_forward(start = :head, count = page_size)
|
35
43
|
event_store.read_all_streams_forward(start, count)
|
36
44
|
end
|
37
45
|
alias :read_all_streams :read_all_streams_forward
|
38
46
|
|
47
|
+
def read_all_streams_backward(start = :head, count = page_size)
|
48
|
+
event_store.read_all_streams_backward(start, count)
|
49
|
+
end
|
50
|
+
|
39
51
|
def subscribe(subscriber, event_types)
|
40
52
|
event_store.subscribe(subscriber, event_types)
|
41
53
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_event_store
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- rybex
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-05-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -190,6 +190,7 @@ files:
|
|
190
190
|
- ".gitignore"
|
191
191
|
- ".travis.yml"
|
192
192
|
- CHANGELOG.md
|
193
|
+
- CONTRIBUTING.md
|
193
194
|
- Gemfile
|
194
195
|
- LICENSE
|
195
196
|
- README.md
|