event_store_client 0.1.15 → 0.1.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/event_store_client/broker.rb +1 -5
- data/lib/event_store_client/connection.rb +12 -13
- data/lib/event_store_client/store_adapter/api/client.rb +24 -3
- data/lib/event_store_client/subscription.rb +12 -6
- data/lib/event_store_client/subscriptions.rb +9 -7
- data/lib/event_store_client/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b27db234d64f8cbe377e6eb65b5b194c7b42178bf4201323baae5ac6a7e99f57
|
4
|
+
data.tar.gz: b4df0eaec15c72dbaeccd1fa64485a23df385f889e5d448e1cd24be96913ed65
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c0f0760c3c0ce01b39dc8c9501b8112c38f911ab4415bd64fda77cda17d0e5684d4f8d362d3f1728939a6ad85b88bba3a71a2161d3399999ea425a781893564
|
7
|
+
data.tar.gz: 7a5d1d6983f90d6ad38c4b57323f4290934f38e687b1302e712b9a0723b26d873ce49128d3341a6334ac62abe0c8896608943012b679d4788bac778bcdc35742
|
@@ -6,11 +6,7 @@ module EventStoreClient
|
|
6
6
|
subscriptions.each do |subscription|
|
7
7
|
new_events = connection.consume_feed(subscription.stream, subscription.name)
|
8
8
|
next if new_events.none?
|
9
|
-
new_events.each
|
10
|
-
subscription.subscribers.each do |subscriber|
|
11
|
-
subscriber.call(event)
|
12
|
-
end
|
13
|
-
end
|
9
|
+
new_events.each { |event| subscription.subscriber.call(event) }
|
14
10
|
end
|
15
11
|
end
|
16
12
|
|
@@ -19,6 +19,10 @@ module EventStoreClient
|
|
19
19
|
|
20
20
|
def delete_stream(stream); end
|
21
21
|
|
22
|
+
def join_streams(name, streams)
|
23
|
+
client.join_streams(name, streams)
|
24
|
+
end
|
25
|
+
|
22
26
|
def subscribe(stream, name:)
|
23
27
|
client.subscribe_to_stream(stream, name)
|
24
28
|
end
|
@@ -27,18 +31,12 @@ module EventStoreClient
|
|
27
31
|
response = client.consume_feed(stream, subscription)
|
28
32
|
return [] unless response.body
|
29
33
|
body = JSON.parse(response.body)
|
30
|
-
|
31
|
-
|
32
|
-
|
34
|
+
|
35
|
+
ack = body['links'].find { |link| link['relation'] == 'ackAll' }
|
36
|
+
return unless ack
|
37
|
+
ack_uri = ack['uri']
|
33
38
|
events = body['entries'].map do |entry|
|
34
|
-
|
35
|
-
id: entry['eventId'],
|
36
|
-
title: entry['title'],
|
37
|
-
type: entry['eventType'],
|
38
|
-
data: entry['data'] || '{}',
|
39
|
-
metadata: entry['isMetaData'] ? entry['metaData'] : '{}'
|
40
|
-
)
|
41
|
-
mapper.deserialize(event)
|
39
|
+
deserialize_event(entry)
|
42
40
|
end
|
43
41
|
client.ack(ack_uri)
|
44
42
|
events
|
@@ -112,9 +110,10 @@ module EventStoreClient
|
|
112
110
|
id: entry['eventId'],
|
113
111
|
title: entry['title'],
|
114
112
|
type: entry['eventType'],
|
115
|
-
data: entry['data'],
|
116
|
-
metadata: entry['metaData']
|
113
|
+
data: entry['data'] || '{}',
|
114
|
+
metadata: entry['isMetaData'] ? entry['metaData'] : '{}'
|
117
115
|
)
|
116
|
+
|
118
117
|
mapper.deserialize(event)
|
119
118
|
end
|
120
119
|
end
|
@@ -38,6 +38,24 @@ module EventStoreClient
|
|
38
38
|
)
|
39
39
|
end
|
40
40
|
|
41
|
+
def join_streams(name, streams)
|
42
|
+
data = <<~STRING
|
43
|
+
fromStreams(#{streams})
|
44
|
+
.when({
|
45
|
+
$any: function(s,e) {
|
46
|
+
linkTo("#{name}", e)
|
47
|
+
}
|
48
|
+
})
|
49
|
+
STRING
|
50
|
+
|
51
|
+
make_request(
|
52
|
+
:post,
|
53
|
+
"/projections/continuous?name=#{name}&type=js&enabled=true&emit=true%26trackemittedstreams=true", # rubocop:disable Metrics/LineLength
|
54
|
+
body: data,
|
55
|
+
headers: {}
|
56
|
+
)
|
57
|
+
end
|
58
|
+
|
41
59
|
def subscribe_to_stream(
|
42
60
|
stream_name, subscription_name, stats: true, start_from: 0, retries: 5
|
43
61
|
)
|
@@ -48,7 +66,7 @@ module EventStoreClient
|
|
48
66
|
extraStatistics: stats,
|
49
67
|
startFrom: start_from,
|
50
68
|
maxRetryCount: retries,
|
51
|
-
|
69
|
+
resolveLinktos: true
|
52
70
|
},
|
53
71
|
headers: {
|
54
72
|
'Content-Type' => 'application/json'
|
@@ -60,11 +78,14 @@ module EventStoreClient
|
|
60
78
|
stream_name,
|
61
79
|
subscription_name,
|
62
80
|
count: 1,
|
63
|
-
long_poll: 0
|
81
|
+
long_poll: 0,
|
82
|
+
resolve_links: true
|
64
83
|
)
|
65
84
|
headers = long_poll.positive? ? { 'ES-LongPoll' => long_poll.to_s } : {}
|
66
85
|
headers['Content-Type'] = 'application/vnd.eventstore.competingatom+json'
|
67
86
|
headers['Accept'] = 'application/vnd.eventstore.competingatom+json'
|
87
|
+
headers['ES-ResolveLinkTos'] = resolve_links.to_s
|
88
|
+
|
68
89
|
make_request(
|
69
90
|
:get,
|
70
91
|
"/subscriptions/#{stream_name}/#{subscription_name}/#{count}",
|
@@ -126,7 +147,7 @@ module EventStoreClient
|
|
126
147
|
method = RequestMethod.new(method_name)
|
127
148
|
connection.send(method.to_s, path) do |req|
|
128
149
|
req.headers = req.headers.merge(headers)
|
129
|
-
req.body = body.to_json
|
150
|
+
req.body = body.is_a?(String) ? body : body.to_json
|
130
151
|
req.params['embed'] = 'body' if method == :get
|
131
152
|
end
|
132
153
|
end
|
@@ -2,15 +2,21 @@
|
|
2
2
|
|
3
3
|
module EventStoreClient
|
4
4
|
class Subscription
|
5
|
-
|
6
|
-
attr_reader :stream, :name
|
5
|
+
attr_reader :stream, :subscriber, :name, :observed_streams
|
7
6
|
|
8
7
|
private
|
9
8
|
|
10
|
-
def initialize(
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
def initialize(subscriber, service:, event_types:)
|
10
|
+
subscriber_class =
|
11
|
+
if subscriber.class.name == 'Class'
|
12
|
+
subscriber.name
|
13
|
+
else
|
14
|
+
subscriber.class.name
|
15
|
+
end
|
16
|
+
@name = "#{service}-#{subscriber_class}"
|
17
|
+
@subscriber = subscriber
|
18
|
+
@stream = name
|
19
|
+
@observed_streams = event_types.reduce([]) { |r, type| r << "$et-#{type}" }
|
14
20
|
end
|
15
21
|
end
|
16
22
|
end
|
@@ -3,16 +3,17 @@
|
|
3
3
|
module EventStoreClient
|
4
4
|
class Subscriptions
|
5
5
|
def create(subscriber, event_types)
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
create_subscription(subscription)
|
10
|
-
@subscriptions[type.to_s] = subscription
|
6
|
+
subscription = Subscription.new(subscriber, event_types: event_types, service: service)
|
7
|
+
connection.join_streams(subscriber.class.name, subscription.observed_streams)
|
8
|
+
unless @subscriptions.detect { |sub| sub.name == subscription.name }
|
9
|
+
create_subscription(subscription)
|
11
10
|
end
|
11
|
+
|
12
|
+
subscriptions << subscription
|
12
13
|
end
|
13
14
|
|
14
15
|
def each
|
15
|
-
subscriptions.
|
16
|
+
subscriptions.each do |subscription|
|
16
17
|
yield(subscription)
|
17
18
|
end
|
18
19
|
end
|
@@ -24,6 +25,7 @@ module EventStoreClient
|
|
24
25
|
private
|
25
26
|
|
26
27
|
def create_subscription(subscription)
|
28
|
+
connection.join_streams(subscription.name, subscription.observed_streams)
|
27
29
|
connection.subscribe(subscription.stream, name: subscription.name)
|
28
30
|
end
|
29
31
|
|
@@ -32,7 +34,7 @@ module EventStoreClient
|
|
32
34
|
def initialize(connection:, service: 'default')
|
33
35
|
@connection = connection
|
34
36
|
@service = service
|
35
|
-
@subscriptions =
|
37
|
+
@subscriptions = []
|
36
38
|
end
|
37
39
|
end
|
38
40
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: event_store_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sebastian Wilgosz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-schema
|