ruby_event_store 2.17.1 → 2.19.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 584a718972b372e273512e4af2e7da9448c4b6d95f8a38f2e97f86dcf75a4bb8
4
- data.tar.gz: f29d2fe958a8a214f6d1e80491130b429ceb9cab0a26b507f5b47f1284592ee5
3
+ metadata.gz: 7f21bbf176c36c5948ac817d5e6cf13972d608c25eeb11d691831ba3a51f09bd
4
+ data.tar.gz: f9cd6d162d9927454ccd9bba582d53644a83a635c775c515283ea32654209652
5
5
  SHA512:
6
- metadata.gz: 3565b061885fb4dd9cec8adbe77fcf0f87f9f810e5c5792626bc50f701fdfafdb464bd2bccdf5686a7617e8c3be2d7b5af47b4b6b8d9e887ae5189c283c7573e
7
- data.tar.gz: be7a632720eb7c60deb0da18171a45a58cce1e53df18be9707bc237a382ba1d7116313f2e7a277a2bf9ca7a3bf98b434c98f56d814b1b051974dd9ccd6fc5c8f
6
+ metadata.gz: 5cbe530dace472f1e46a7bfe52cdfb11adb0b4f4b38e59fb448fb68d679fdd5a8cd76be0dc6fdcc29ecb6d4e316845d6022eafd4499cc303e66601c64336556a
7
+ data.tar.gz: b1288e6f0a95d0eb90550f089a791b6e23583f4939426bdc655e63d94814837187b95cd81860c07de666be07063667dcf1823103bbae3cbede2d6d075077ef0a
@@ -18,7 +18,7 @@ module RubyEventStore
18
18
  @mapper = batch_mapper?(mapper) ? mapper : Mappers::BatchMapper.new(mapper)
19
19
  @broker =
20
20
  message_broker ||
21
- Broker.new(subscriptions: subscriptions || Subscriptions.new, dispatcher: dispatcher || Dispatcher.new)
21
+ Broker.new(subscriptions: subscriptions || Subscriptions.new, dispatcher: dispatcher || SyncScheduler.new)
22
22
  @clock = clock
23
23
  @metadata = Concurrent::ThreadLocalVar.new
24
24
  @correlation_id_generator = correlation_id_generator
@@ -33,7 +33,7 @@ module RubyEventStore
33
33
  event_store = RubyEventStore::Client.new(
34
34
  message_broker: RubyEventStore::Broker.new(
35
35
  subscriptions: RubyEventStore::Subscriptions.new,
36
- dispatcher: RubyEventStore::Dispatcher.new
36
+ dispatcher: RubyEventStore::SyncScheduler.new
37
37
  )
38
38
  )
39
39
  EOW
@@ -46,15 +46,15 @@ module RubyEventStore
46
46
  end
47
47
 
48
48
  def rescue_from_double_json_serialization!
49
- return unless repository.respond_to? :rescue_from_double_json_serialization!
50
- repository.rescue_from_double_json_serialization!
49
+ return unless @repository.respond_to? :rescue_from_double_json_serialization!
50
+ @repository.rescue_from_double_json_serialization!
51
51
  end
52
52
 
53
53
  # Persists events and notifies subscribed handlers about them
54
54
  #
55
55
  # @param events [Array<Event>, Event] event(s)
56
56
  # @param stream_name [String] name of the stream for persisting events.
57
- # @param expected_version [:any, :auto, :none, Integer] controls optimistic locking strategy. {http://railseventstore.org/docs/expected_version/ Read more}
57
+ # @param expected_version [:any, :auto, :none, Integer] controls optimistic locking strategy. {https://railseventstore.org/docs/core-concepts/expected-version Read more}
58
58
  # @return [self]
59
59
  def publish(events, topic: nil, stream_name: GLOBAL_STREAM, expected_version: :any)
60
60
  enriched_events = enrich_events_metadata(events)
@@ -62,15 +62,15 @@ module RubyEventStore
62
62
  append_records_to_stream(records, stream_name: stream_name, expected_version: expected_version)
63
63
  enriched_events.zip(records) do |event, record|
64
64
  with_metadata(correlation_id: event.metadata.fetch(:correlation_id), causation_id: event.event_id) do
65
- if broker.public_method(:call).arity == 3
66
- broker.call(topic || event.event_type, event, record)
65
+ if @broker.public_method(:call).arity == 3
66
+ @broker.call(topic || event.event_type, event, record)
67
67
  else
68
68
  warn <<~EOW
69
69
  Message broker shall support topics.
70
70
  Topic WILL BE IGNORED in the current broker.
71
71
  Modify the broker implementation to pass topic as an argument to broker.call method.
72
72
  EOW
73
- broker.call(event, record)
73
+ @broker.call(event, record)
74
74
  end
75
75
  end
76
76
  end
@@ -98,7 +98,12 @@ module RubyEventStore
98
98
  # @param expected_version (see #publish)
99
99
  # @return [self]
100
100
  def link(event_ids, stream_name:, expected_version: :any)
101
- repository.link_to_stream(Array(event_ids), Stream.new(stream_name), ExpectedVersion.new(expected_version))
101
+ if event_ids.nil? || Array(event_ids).any?(&:nil?)
102
+ warn <<~EOW
103
+ Passing `nil` to link is deprecated and will raise ArgumentError in RubyEventStore 3.0.
104
+ EOW
105
+ end
106
+ @repository.link_to_stream(Array(event_ids), Stream.new(stream_name), ExpectedVersion.new(expected_version))
102
107
  self
103
108
  end
104
109
 
@@ -109,23 +114,23 @@ module RubyEventStore
109
114
  # @param stream_name [String] name of the stream to be cleared.
110
115
  # @return [self]
111
116
  def delete_stream(stream_name)
112
- repository.delete_stream(Stream.new(stream_name))
117
+ @repository.delete_stream(Stream.new(stream_name))
113
118
  self
114
119
  end
115
120
 
116
121
  # Starts building a query specification for reading events.
117
- # {http://railseventstore.org/docs/read/ More info.}
122
+ # {https://railseventstore.org/docs/core-concepts/read More info.}
118
123
  #
119
124
  # @return [Specification]
120
125
  def read
121
- Specification.new(SpecificationReader.new(repository, mapper))
126
+ Specification.new(SpecificationReader.new(@repository, @mapper))
122
127
  end
123
128
 
124
129
  # Gets list of streams where event is stored or linked
125
130
  #
126
131
  # @return [Array<Stream>] where event is stored or linked
127
132
  def streams_of(event_id)
128
- repository.streams_of(event_id)
133
+ @repository.streams_of(event_id)
129
134
  end
130
135
 
131
136
  # Gets position of the event in given stream
@@ -137,9 +142,9 @@ module RubyEventStore
137
142
  # @param event_id [String]
138
143
  # @param stream_name [String]
139
144
  # @return [Integer] nonnegative integer position of event in stream
140
- # @raise [EventNotInStream]
145
+ # @raise [EventNotFoundInStream]
141
146
  def position_in_stream(event_id, stream_name)
142
- repository.position_in_stream(event_id, Stream.new(stream_name))
147
+ @repository.position_in_stream(event_id, Stream.new(stream_name))
143
148
  end
144
149
 
145
150
  # Gets position of the event in global stream
@@ -152,7 +157,7 @@ module RubyEventStore
152
157
  # @raise [EventNotFound]
153
158
  # @return [Integer] nonnegno ative integer position of event in global stream
154
159
  def global_position(event_id)
155
- repository.global_position(event_id)
160
+ @repository.global_position(event_id)
156
161
  end
157
162
 
158
163
  # Checks whether event is linked in given stream
@@ -162,7 +167,7 @@ module RubyEventStore
162
167
  # @return [Boolean] true if event is linked to given stream, false otherwise
163
168
  def event_in_stream?(event_id, stream_name)
164
169
  stream = Stream.new(stream_name)
165
- stream.global? ? repository.has_event?(event_id) : repository.event_in_stream?(event_id, stream)
170
+ stream.global? ? @repository.has_event?(event_id) : @repository.event_in_stream?(event_id, stream)
166
171
  end
167
172
 
168
173
  # Subscribes a handler (subscriber) that will be invoked for published events of provided type.
@@ -180,7 +185,7 @@ module RubyEventStore
180
185
  def subscribe(subscriber = nil, to:, &proc)
181
186
  raise ArgumentError, "subscriber must be first argument or block, cannot be both" if subscriber && proc
182
187
  subscriber ||= proc
183
- broker.add_subscription(subscriber, to.map { |event_klass| event_type_resolver.call(event_klass) })
188
+ @broker.add_subscription(subscriber, to.map { |event_klass| @event_type_resolver.call(event_klass) })
184
189
  end
185
190
 
186
191
  # Subscribes a handler (subscriber) that will be invoked for all published events
@@ -195,7 +200,7 @@ module RubyEventStore
195
200
  # @raise [ArgumentError, SubscriberNotExist]
196
201
  def subscribe_to_all_events(subscriber = nil, &proc)
197
202
  raise ArgumentError, "subscriber must be first argument or block, cannot be both" if subscriber && proc
198
- broker.add_global_subscription(subscriber || proc)
203
+ @broker.add_global_subscription(subscriber || proc)
199
204
  end
200
205
 
201
206
  # Get list of handlers subscribed to an event
@@ -203,7 +208,7 @@ module RubyEventStore
203
208
  # @param to [Class, String] type of events to get list of sybscribed handlers
204
209
  # @return [Array<Object, Class>]
205
210
  def subscribers_for(event_class)
206
- broker.all_subscriptions_for(event_type_resolver.call(event_class))
211
+ @broker.all_subscriptions_for(@event_type_resolver.call(event_class))
207
212
  end
208
213
 
209
214
  # Builder object for collecting temporary handlers (subscribers)
@@ -222,7 +227,7 @@ module RubyEventStore
222
227
  # will be called for all published events.
223
228
  # The subscription is active only during the invocation
224
229
  # of the block of code provided to {Client#within}.
225
- # {http://railseventstore.org/docs/subscribe/#temporary-subscriptions Read more.}
230
+ # {https://railseventstore.org/docs/core-concepts/subscribe#temporary-subscriptions Read more.}
226
231
  #
227
232
  # @param handlers [Object, Class] handlers passed as objects or classes
228
233
  # @param handler2 [Proc] handler passed as proc
@@ -237,7 +242,7 @@ module RubyEventStore
237
242
  # will be called for published events of provided type.
238
243
  # The subscription is active only during the invocation
239
244
  # of the block of code provided to {Client#within}.
240
- # {http://railseventstore.org/docs/subscribe/#temporary-subscriptions Read more.}
245
+ # {https://railseventstore.org/docs/core-concepts/subscribe#temporary-subscriptions Read more.}
241
246
  #
242
247
  # @overload subscribe(handler, to:)
243
248
  # @param handler [Object, Class] handler passed as objects or classes
@@ -255,7 +260,7 @@ module RubyEventStore
255
260
 
256
261
  # Invokes the block of code provided to {Client#within}
257
262
  # and then unsubscribes temporary handlers.
258
- # {http://railseventstore.org/docs/subscribe/#temporary-subscriptions Read more.}
263
+ # {https://railseventstore.org/docs/core-concepts/subscribe#temporary-subscriptions Read more.}
259
264
  #
260
265
  # @return [Object] value returned by the invoked block of code
261
266
  def call
@@ -280,17 +285,17 @@ module RubyEventStore
280
285
  end
281
286
 
282
287
  # Use for starting temporary subscriptions.
283
- # {http://railseventstore.org/docs/subscribe/#temporary-subscriptions Read more}
288
+ # {https://railseventstore.org/docs/core-concepts/subscribe#temporary-subscriptions Read more}
284
289
  #
285
290
  # @param block [Proc] block of code during which the temporary subscriptions will be active
286
291
  # @return [Within] builder object which collects temporary subscriptions
287
292
  def within(&block)
288
293
  raise ArgumentError if block.nil?
289
- Within.new(block, broker, event_type_resolver)
294
+ Within.new(block, @broker, @event_type_resolver)
290
295
  end
291
296
 
292
297
  # Set additional metadata for all events published within the provided block
293
- # {http://railseventstore.org/docs/request_metadata#passing-your-own-metadata-using-with_metadata-method Read more}
298
+ # {https://railseventstore.org/docs/core-concepts/request-metadata#passing-your-own-metadata-using-with_metadata Read more}
294
299
  #
295
300
  # @param metadata [Hash] metadata to set for events
296
301
  # @param block [Proc] block of code during which the metadata will be added
@@ -304,13 +309,13 @@ module RubyEventStore
304
309
  end
305
310
 
306
311
  # Deserialize event which was serialized for async event handlers
307
- # {http://railseventstore.org/docs/subscribe/#async-handlers Read more}
312
+ # {https://railseventstore.org/docs/core-concepts/subscribe#async-handlers Read more}
308
313
  #
309
314
  # @return [Event] deserialized event
310
315
  def deserialize(serializer:, event_type:, event_id:, data:, metadata:, timestamp: nil, valid_at: nil)
311
316
  extract_timestamp = lambda { |m| (m[:timestamp] || Time.parse(m.fetch("timestamp"))).iso8601 }
312
317
 
313
- mapper.records_to_events(
318
+ @mapper.records_to_events(
314
319
  [
315
320
  SerializedRecord.new(
316
321
  event_type: event_type,
@@ -325,7 +330,7 @@ module RubyEventStore
325
330
  end
326
331
 
327
332
  # Read additional metadata which will be added for published events
328
- # {http://railseventstore.org/docs/request_metadata#passing-your-own-metadata-using-with_metadata-method Read more}
333
+ # {https://railseventstore.org/docs/core-concepts/request-metadata#passing-your-own-metadata-using-with_metadata Read more}
329
334
  #
330
335
  # @return [Hash]
331
336
  def metadata
@@ -337,7 +342,7 @@ module RubyEventStore
337
342
  # Does not notify any subscribed handlers.
338
343
  # Does not enrich with additional current metadata.
339
344
  # Does not allow changing which streams these events are in.
340
- # {http://railseventstore.org/docs/migrating_messages Read more}
345
+ # {https://railseventstore.org/docs/advanced-topics/migrating-existing-events Read more}
341
346
  #
342
347
  # @example Add data and metadata to existing events
343
348
  #
@@ -362,7 +367,7 @@ module RubyEventStore
362
367
  # @param events [Array<Event>, Event] event(s) to serialize and overwrite again
363
368
  # @return [self]
364
369
  def overwrite(events_or_event)
365
- repository.update_messages(transform(Array(events_or_event)))
370
+ @repository.update_messages(transform(Array(events_or_event)))
366
371
  self
367
372
  end
368
373
 
@@ -376,23 +381,28 @@ module RubyEventStore
376
381
  private
377
382
 
378
383
  def transform(events)
379
- mapper.events_to_records(events)
384
+ @mapper.events_to_records(events)
380
385
  end
381
386
 
382
387
  def enrich_events_metadata(events)
388
+ if events.nil? || Array(events).any?(&:nil?)
389
+ warn <<~EOW
390
+ Passing `nil` to publish/append is deprecated and will raise ArgumentError in RubyEventStore 3.0.
391
+ EOW
392
+ end
383
393
  events = Array(events)
384
394
  events.each { |event| enrich_event_metadata(event) }
385
395
  end
386
396
 
387
397
  def enrich_event_metadata(event)
388
398
  metadata.each { |key, value| event.metadata[key] ||= value }
389
- event.metadata[:timestamp] ||= clock.call
399
+ event.metadata[:timestamp] ||= @clock.call
390
400
  event.metadata[:valid_at] ||= event.metadata.fetch(:timestamp)
391
- event.metadata[:correlation_id] ||= correlation_id_generator.call
401
+ event.metadata[:correlation_id] ||= @correlation_id_generator.call
392
402
  end
393
403
 
394
404
  def append_records_to_stream(records, stream_name:, expected_version:)
395
- repository.append_to_stream(records, Stream.new(stream_name), ExpectedVersion.new(expected_version))
405
+ @repository.append_to_stream(records, Stream.new(stream_name), ExpectedVersion.new(expected_version))
396
406
  end
397
407
 
398
408
  protected
@@ -412,7 +422,5 @@ module RubyEventStore
412
422
  def default_correlation_id_generator
413
423
  -> { SecureRandom.uuid }
414
424
  end
415
-
416
- attr_reader :repository, :mapper, :broker, :clock, :correlation_id_generator, :event_type_resolver
417
425
  end
418
426
  end
@@ -1,20 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyEventStore
4
- class Dispatcher
5
- def call(subscriber, event, _)
6
- subscriber = subscriber.new if Class === subscriber
7
- subscriber.call(event)
8
- end
9
-
10
- def verify(subscriber)
11
- begin
12
- subscriber_instance = Class === subscriber ? subscriber.new : subscriber
13
- rescue ArgumentError
14
- false
15
- else
16
- subscriber_instance.respond_to?(:call)
17
- end
4
+ class Dispatcher < SyncScheduler
5
+ def initialize
6
+ warn <<~EOW
7
+ DEPRECATION WARNING: `RubyEventStore::Dispatcher` is deprecated and will be removed in the next major release.
8
+ Use `RubyEventStore::SyncScheduler` instead.
9
+ EOW
18
10
  end
19
11
  end
20
12
  end
@@ -78,7 +78,7 @@ module RubyEventStore
78
78
  end
79
79
 
80
80
  # Reads correlation_id from metadata.
81
- # {http://railseventstore.org/docs/correlation_causation/ Find out more}
81
+ # {https://railseventstore.org/docs/core-concepts/correlation-causation Find out more}
82
82
  #
83
83
  # @return [String, nil]
84
84
  def correlation_id
@@ -86,7 +86,7 @@ module RubyEventStore
86
86
  end
87
87
 
88
88
  # Sets correlation_id in metadata.
89
- # {http://railseventstore.org/docs/correlation_causation/ Find out more}
89
+ # {https://railseventstore.org/docs/core-concepts/correlation-causation Find out more}
90
90
  #
91
91
  # @param val [String]
92
92
  # @return [String]
@@ -95,7 +95,7 @@ module RubyEventStore
95
95
  end
96
96
 
97
97
  # Reads causation_id from metadata.
98
- # {http://railseventstore.org/docs/correlation_causation/ Find out more}
98
+ # {https://railseventstore.org/docs/core-concepts/correlation-causation Find out more}
99
99
  #
100
100
  # @return [String, nil]
101
101
  def causation_id
@@ -103,7 +103,7 @@ module RubyEventStore
103
103
  end
104
104
 
105
105
  # Sets causation_id= in metadata.
106
- # {http://railseventstore.org/docs/correlation_causation/ Find out more}
106
+ # {https://railseventstore.org/docs/core-concepts/correlation-causation Find out more}
107
107
  #
108
108
  # @param val [String]
109
109
  # @return [String]
@@ -113,7 +113,7 @@ module RubyEventStore
113
113
 
114
114
  # Sets correlation_id and causation_id in metadata based
115
115
  # on correlation_id and message_id of the provided message.
116
- # {http://railseventstore.org/docs/correlation_causation/ Find out more}
116
+ # {https://railseventstore.org/docs/core-concepts/correlation-causation Find out more}
117
117
  #
118
118
  # @param other_message [Event, command] message to correlate with. Most likely an event or a command. Must respond to correlation_id and message_id.
119
119
  # @return [String] set causation_id
@@ -123,6 +123,21 @@ module RubyEventStore
123
123
  self
124
124
  end
125
125
 
126
+ # Returns a hash of the name/value pairs for the given event attributes.
127
+ #
128
+ # @param attributes [Array] attributes to deconstruct
129
+ # @return [Hash] deconstructed event
130
+ def deconstruct_keys(attributes)
131
+ {
132
+ causation_id: causation_id,
133
+ correlation_id: correlation_id,
134
+ data: data,
135
+ event_id: event_id,
136
+ event_type: event_type,
137
+ metadata: metadata.to_h
138
+ }.slice(*attributes)
139
+ end
140
+
126
141
  alias_method :eql?, :==
127
142
  end
128
143
  end
@@ -1,17 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyEventStore
4
- class ImmediateAsyncDispatcher
4
+ class ImmediateAsyncDispatcher < ImmediateDispatcher
5
5
  def initialize(scheduler:)
6
- @scheduler = scheduler
7
- end
8
-
9
- def call(subscriber, _, record)
10
- @scheduler.call(subscriber, record)
11
- end
12
-
13
- def verify(subscriber)
14
- @scheduler.verify(subscriber)
6
+ warn <<~EOW
7
+ DEPRECATION WARNING: `RubyEventStore::ImmediateAsyncDispatcher` is deprecated and will be removed in the next major release.
8
+ Use `RubyEventStore::ImmediateDispatcher` instead.
9
+ EOW
10
+ super
15
11
  end
16
12
  end
17
13
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyEventStore
4
+ class ImmediateDispatcher
5
+ def initialize(scheduler:)
6
+ @scheduler = scheduler
7
+ end
8
+
9
+ def call(subscriber, _, record)
10
+ @scheduler.call(subscriber, record)
11
+ end
12
+
13
+ def verify(subscriber)
14
+ @scheduler.verify(subscriber)
15
+ end
16
+ end
17
+ end
@@ -8,7 +8,7 @@ module RubyEventStore
8
8
  Mixing expected version :any and specific position (or :auto) is unsupported.
9
9
 
10
10
  Read more about expected versions here:
11
- https://railseventstore.org/docs/v2/expected_version/
11
+ https://railseventstore.org/docs/core-concepts/expected-version
12
12
  EOS
13
13
  end
14
14
  end
@@ -100,7 +100,7 @@ module RubyEventStore
100
100
  end
101
101
 
102
102
  def count(spec)
103
- read_scope(spec).count
103
+ read_scope(spec).size # mutant:disable
104
104
  end
105
105
 
106
106
  def update_messages(records)
@@ -234,12 +234,18 @@ module RubyEventStore
234
234
  end
235
235
 
236
236
  def ensure_supported_any_usage(resolved_version, stream)
237
- if @ensure_supported_any_usage
238
- stream_positions = streams.fetch(stream.name, Array.new).map(&:position)
239
- if resolved_version.nil?
240
- raise UnsupportedVersionAnyUsage if !stream_positions.compact.empty?
237
+ stream_positions = streams.fetch(stream.name, Array.new).map(&:position)
238
+ violation =
239
+ (resolved_version.nil? && !stream_positions.compact.empty?) ||
240
+ (!resolved_version.nil? && stream_positions.include?(nil))
241
+
242
+ if violation
243
+ if @ensure_supported_any_usage
244
+ raise UnsupportedVersionAnyUsage
241
245
  else
242
- raise UnsupportedVersionAnyUsage if stream_positions.include?(nil)
246
+ warn <<~EOW
247
+ Mixing expected version :any and specific position (or :auto) is deprecated and will raise UnsupportedVersionAnyUsage in RubyEventStore 3.0.
248
+ EOW
243
249
  end
244
250
  end
245
251
  end
@@ -2,55 +2,75 @@
2
2
 
3
3
  module RubyEventStore
4
4
  class InstrumentedBroker
5
+ DEPRECATION_MESSAGE = <<~EOW
6
+ Instrumentation event names *.rails_event_store are deprecated and will be removed in the next major release.
7
+ Use *.ruby_event_store instead.
8
+ EOW
9
+ private_constant :DEPRECATION_MESSAGE
10
+
5
11
  def initialize(broker, instrumentation)
6
12
  @broker = broker
7
13
  @instrumentation = instrumentation
8
14
  end
9
15
 
10
16
  def call(topic, event, record)
11
- instrumentation.instrument("call.broker.rails_event_store", topic: topic, event: event, record: record) do
12
- if broker.public_method(:call).arity == 3
13
- broker.call(topic, event, record)
14
- else
15
- warn <<~EOW
16
- Message broker shall support topics.
17
- Topic WILL BE IGNORED in the current broker.
18
- Modify the broker implementation to pass topic as an argument to broker.call method.
19
- EOW
20
- broker.call(event, record)
17
+ instrumentation.instrument("call.broker.ruby_event_store", topic: topic, event: event, record: record) do
18
+ deprecated_instrument("call.broker.rails_event_store", topic: topic, event: event, record: record) do
19
+ if broker.public_method(:call).arity == 3
20
+ broker.call(topic, event, record)
21
+ else
22
+ warn <<~EOW
23
+ Message broker shall support topics.
24
+ Topic WILL BE IGNORED in the current broker.
25
+ Modify the broker implementation to pass topic as an argument to broker.call method.
26
+ EOW
27
+ broker.call(event, record)
28
+ end
21
29
  end
22
30
  end
23
31
  end
24
32
 
25
33
  def add_subscription(subscriber, topics)
26
- instrumentation.instrument("add_subscription.broker.rails_event_store", subscriber: subscriber, topics: topics) do
27
- broker.add_subscription(subscriber, topics)
34
+ instrumentation.instrument("add_subscription.broker.ruby_event_store", subscriber: subscriber, topics: topics) do
35
+ deprecated_instrument("add_subscription.broker.rails_event_store", subscriber: subscriber, topics: topics) do
36
+ broker.add_subscription(subscriber, topics)
37
+ end
28
38
  end
29
39
  end
30
40
 
31
41
  def add_global_subscription(subscriber)
32
- instrumentation.instrument("add_global_subscription.broker.rails_event_store", subscriber: subscriber) do
33
- broker.add_global_subscription(subscriber)
42
+ instrumentation.instrument("add_global_subscription.broker.ruby_event_store", subscriber: subscriber) do
43
+ deprecated_instrument("add_global_subscription.broker.rails_event_store", subscriber: subscriber) do
44
+ broker.add_global_subscription(subscriber)
45
+ end
34
46
  end
35
47
  end
36
48
 
37
49
  def add_thread_subscription(subscriber, topics)
38
50
  instrumentation.instrument(
39
- "add_thread_subscription.broker.rails_event_store",
51
+ "add_thread_subscription.broker.ruby_event_store",
40
52
  subscriber: subscriber,
41
53
  topics: topics,
42
- ) { broker.add_thread_subscription(subscriber, topics) }
54
+ ) do
55
+ deprecated_instrument("add_thread_subscription.broker.rails_event_store", subscriber: subscriber, topics: topics) do
56
+ broker.add_thread_subscription(subscriber, topics)
57
+ end
58
+ end
43
59
  end
44
60
 
45
61
  def add_thread_global_subscription(subscriber)
46
- instrumentation.instrument("add_thread_global_subscription.broker.rails_event_store", subscriber: subscriber) do
47
- broker.add_thread_global_subscription(subscriber)
62
+ instrumentation.instrument("add_thread_global_subscription.broker.ruby_event_store", subscriber: subscriber) do
63
+ deprecated_instrument("add_thread_global_subscription.broker.rails_event_store", subscriber: subscriber) do
64
+ broker.add_thread_global_subscription(subscriber)
65
+ end
48
66
  end
49
67
  end
50
68
 
51
69
  def all_subscriptions_for(topic)
52
- instrumentation.instrument("all_subscriptions_for.broker.rails_event_store", topic: topic) do
53
- broker.all_subscriptions_for(topic)
70
+ instrumentation.instrument("all_subscriptions_for.broker.ruby_event_store", topic: topic) do
71
+ deprecated_instrument("all_subscriptions_for.broker.rails_event_store", topic: topic) do
72
+ broker.all_subscriptions_for(topic)
73
+ end
54
74
  end
55
75
  end
56
76
 
@@ -69,5 +89,17 @@ module RubyEventStore
69
89
  private
70
90
 
71
91
  attr_reader :instrumentation, :broker
92
+
93
+ def deprecated_instrument(name, payload, &block)
94
+ canonical_name = name.sub("rails_event_store", "ruby_event_store")
95
+ old_listeners = instrumentation.notifier.all_listeners_for(name)
96
+ new_listeners = instrumentation.notifier.all_listeners_for(canonical_name)
97
+ if (old_listeners - new_listeners).any?
98
+ warn DEPRECATION_MESSAGE
99
+ instrumentation.instrument(name, payload, &block)
100
+ else
101
+ yield
102
+ end
103
+ end
72
104
  end
73
105
  end
@@ -2,14 +2,22 @@
2
2
 
3
3
  module RubyEventStore
4
4
  class InstrumentedDispatcher
5
+ DEPRECATION_MESSAGE = <<~EOW
6
+ Instrumentation event names *.rails_event_store are deprecated and will be removed in the next major release.
7
+ Use *.ruby_event_store instead.
8
+ EOW
9
+ private_constant :DEPRECATION_MESSAGE
10
+
5
11
  def initialize(dispatcher, instrumentation)
6
12
  @dispatcher = dispatcher
7
13
  @instrumentation = instrumentation
8
14
  end
9
15
 
10
16
  def call(subscriber, event, record)
11
- instrumentation.instrument("call.dispatcher.rails_event_store", event: event, subscriber: subscriber) do
12
- dispatcher.call(subscriber, event, record)
17
+ instrumentation.instrument("call.dispatcher.ruby_event_store", event: event, subscriber: subscriber) do
18
+ deprecated_instrument("call.dispatcher.rails_event_store", event: event, subscriber: subscriber) do
19
+ dispatcher.call(subscriber, event, record)
20
+ end
13
21
  end
14
22
  end
15
23
 
@@ -28,5 +36,17 @@ module RubyEventStore
28
36
  private
29
37
 
30
38
  attr_reader :instrumentation, :dispatcher
39
+
40
+ def deprecated_instrument(name, payload, &block)
41
+ canonical_name = name.sub("rails_event_store", "ruby_event_store")
42
+ old_listeners = instrumentation.notifier.all_listeners_for(name)
43
+ new_listeners = instrumentation.notifier.all_listeners_for(canonical_name)
44
+ if (old_listeners - new_listeners).any?
45
+ warn DEPRECATION_MESSAGE
46
+ instrumentation.instrument(name, payload, &block)
47
+ else
48
+ yield
49
+ end
50
+ end
31
51
  end
32
52
  end