messaging 3.4.1 → 3.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: cd652caf5be10317afbfc217864ac1fa01ed0297
4
- data.tar.gz: 729a4cefa5be12f689c670f5aa468641de2d9b46
2
+ SHA256:
3
+ metadata.gz: 4e2d081991ad2e8413244571ae8c9f9d3d3d5af9ce48bfcbff424e968c1d5c18
4
+ data.tar.gz: 8ca81941ebd45f6daad6a6c08435598a8b9f0bd3dede7fb99e9cc859a56bb6de
5
5
  SHA512:
6
- metadata.gz: c7c2f6359c96e306acefa7df23306c0816da4badccb446a3f0be46a6d39328fb08d8bf5fceb09d450cc34ee41d43d8629c61c0b462c5ebe73c28a967862d355d
7
- data.tar.gz: 3397a6507517bcbc5b599a68cf1bf7920134d60e89f1d8f901a610cb835cfc11d9ac2d3cbc38bf6f3f411b4d9b5466927ccaa87a82049dd8feba5f5fdef34a21
6
+ metadata.gz: d932b1bfe5c5456e681c21280efbb055eb12acd6bcf5358dfe36d7afaca1bae61da98fbc994ea830a68c2db91230ef6883182b86d482201ae5242f38d19b3280
7
+ data.tar.gz: 6bcf879f6c3a9f2e8353c8877c81340d64e7418b85c84a9003337927402314d4a2cc3b6d279faf25b0ba1d0209a45ef510dd9067cc23bf48cc60a1bd0ab3852c
@@ -58,7 +58,7 @@ jobs:
58
58
  name: run tests
59
59
  command: |
60
60
  ./cc-test-reporter before-build
61
- bundle exec rspec --format RspecJunitFormatter
61
+ bundle exec rspec
62
62
  ./cc-test-reporter after-build --exit-code $?
63
63
 
64
64
  workflows:
@@ -15,7 +15,7 @@ GIT
15
15
  PATH
16
16
  remote: .
17
17
  specs:
18
- messaging (3.4.0)
18
+ messaging (3.4.2)
19
19
  activerecord
20
20
  activesupport
21
21
  bukowskis_after_transaction
@@ -23,6 +23,7 @@ module Messaging
23
23
  self.expected_version = message.expected_version
24
24
  self.message_type = message.message_type
25
25
  self.stream = message.stream_name
26
+ self.stream_category, self.stream_id = message.stream_name.split('$')
26
27
  self.uuid = message.uuid
27
28
  end
28
29
 
@@ -29,7 +29,7 @@ module Messaging
29
29
  def listen_on(topic:)
30
30
  topics = Array(topic).map(&:to_s)
31
31
  Messaging.routes.consumer(name, group_id: group_id) do |c|
32
- topics.each { |t| c.on(/.*/, topic: t, call: self) }
32
+ topics.each { |t| c.on(->(m) { m.topic == t }, call: self) }
33
33
  end
34
34
  end
35
35
 
@@ -28,7 +28,7 @@ module Messaging
28
28
  # the class has been unloaded and update the consumer with the reloaded classes.
29
29
  initializer 'messaging.add_reloader' do |app|
30
30
  app.reloader.after_class_unload do
31
- Messaging.routes.reload_consumer_subscriptions!
31
+ Messaging.routes.reload_consumer_routes!
32
32
  end
33
33
  end
34
34
  end
@@ -25,9 +25,9 @@ module Messaging
25
25
  # Keeps the consumers, but reload their subscriptions so code reloading works.
26
26
  # The consumer has a reference to the class name of each of its handlers,
27
27
  # if the handler is reloaded the reference would point to an old instance.
28
- def reload_consumer_subscriptions!
28
+ def reload_consumer_routes!
29
29
  consumers.each do |c|
30
- c.clear_subscribers!
30
+ c.clear_routes!
31
31
  consumer_definitions[c.name].fetch(:block)&.call(c)
32
32
  end
33
33
  end
@@ -1,13 +1,13 @@
1
1
  require 'messaging/routing/message_matcher'
2
- require 'messaging/routing/subscriber'
3
- require 'messaging/routing/background_job_subscriber'
2
+ require 'messaging/routing/route'
3
+ require 'messaging/routing/enqueued_route'
4
4
  require 'messaging/routing/enqueue_message_handler'
5
5
 
6
6
  module Messaging
7
7
  module Routing
8
- # Public: Sets up subscribers for the events that matches the given pattern
8
+ # Public: Sets up routes for the events that matches the given pattern
9
9
  #
10
- # pattern - Which messages to subscribe to. Can be a string, a regexp,
10
+ # pattern - Which messages to route. Can be a string, a regexp,
11
11
  # a Message class, a module or anything that responds to call.
12
12
  #
13
13
  # call: - Any object that responds to call.
@@ -37,31 +37,31 @@ module Messaging
37
37
  # on ->(m) { m.topic == 'my-topic' }, call: DoSometing, enqueue: DoSomethingElseWithSidekiq
38
38
  # end
39
39
  #
40
- def on(pattern = /.*/, topic: nil, call: nil, enqueue: nil, &block)
41
- subscribers << Subscriber.new(pattern, topic, call) if call
42
- subscribers << Subscriber.new(pattern, topic, block) if block_given?
43
- subscribers << BackgroundJobSubscriber.new(pattern, topic, enqueue) if enqueue
40
+ def on(pattern = /.*/, call: nil, enqueue: nil, &block)
41
+ routes << Route.new(pattern, call) if call
42
+ routes << Route.new(pattern, block) if block_given?
43
+ routes << EnqueuedRoute.new(pattern, enqueue) if enqueue
44
44
  end
45
45
 
46
46
  # Internal: Handles the message with the matching subscribers
47
47
  def handle(message)
48
- subscribers.map { |subscriber| subscriber.call(message) }
48
+ routes.map { |route| route.call(message) }
49
49
  message
50
50
  end
51
51
 
52
52
  # Internal: Used by Rails reloading in development.
53
- def clear_subscribers!
54
- @subscribers = Set.new
53
+ def clear_routes!
54
+ @routes = Set.new
55
55
  end
56
56
 
57
57
  private
58
58
 
59
- def subscribers
60
- @subscribers ||= Set.new
59
+ def routes
60
+ @routes ||= Set.new
61
61
  end
62
62
 
63
63
  def topics
64
- subscribers.flat_map(&:topics).map(&:to_s).uniq
64
+ routes.flat_map(&:topics).map(&:to_s).uniq
65
65
  end
66
66
  end
67
67
  end
@@ -1,8 +1,8 @@
1
1
  module Messaging
2
2
  module Routing
3
3
  # Internal: Used for enqueing background jobs instead of calling the handler directly
4
- class BackgroundJobSubscriber < Subscriber
5
- def initialize(pattern, topic, handler)
4
+ class EnqueuedRoute < Route
5
+ def initialize(pattern, handler)
6
6
  super
7
7
  @handler = EnqueueMessageHandler.new(handler)
8
8
  end
@@ -3,21 +3,17 @@ module Messaging
3
3
  module Routing
4
4
  # Internal: Used by subscribers to match messages.
5
5
  class MessageMatcher
6
- include Dry::Equalizer(:pattern, :topic_pattern)
6
+ include Dry::Equalizer(:pattern)
7
7
 
8
8
  attr_accessor :pattern
9
- attr_accessor :topic_pattern
10
9
 
11
- def initialize(pattern:, topic: nil)
10
+ def initialize(pattern:)
12
11
  self.pattern = pattern
13
- self.topic_pattern = topic
14
12
  end
15
13
 
16
14
  # Internal: See routing.rb for examples on how it is used.
17
-
18
- # Med case statement
19
15
  def matches?(message)
20
- matches_topic?(message) && matches_pattern?(message)
16
+ matches_pattern?(message)
21
17
  end
22
18
 
23
19
  def matches_pattern?(message)
@@ -33,16 +29,6 @@ module Messaging
33
29
  end
34
30
  end
35
31
 
36
- def matches_topic?(message)
37
- return true unless topic_pattern
38
-
39
- case message.topic.to_s
40
- when topic_pattern then true
41
- else
42
- false
43
- end
44
- end
45
-
46
32
  def call(message)
47
33
  matches?(message)
48
34
  end
@@ -55,7 +41,7 @@ module Messaging
55
41
  #
56
42
  # Used by the Kafka adapter to setup consumers.
57
43
  def topics
58
- (Array(topic_pattern) + all_matching_messages.map(&:topic)).uniq
44
+ all_matching_messages.map(&:topic).uniq
59
45
  end
60
46
  end
61
47
  end
@@ -3,14 +3,14 @@ require 'dry-equalizer'
3
3
  module Messaging
4
4
  module Routing
5
5
  # Internal: Used by routing to match a pattern against a callable (handler)
6
- class Subscriber
6
+ class Route
7
7
  include Dry::Equalizer(:matcher, :handler)
8
8
 
9
9
  attr_reader :matcher
10
10
  attr_reader :handler
11
11
 
12
- def initialize(pattern, topic, handler)
13
- @matcher = MessageMatcher.new(pattern: pattern, topic: topic)
12
+ def initialize(pattern, handler)
13
+ @matcher = MessageMatcher.new(pattern: pattern)
14
14
  @handler = handler
15
15
  verify_handler!
16
16
  end
@@ -1,3 +1,3 @@
1
1
  module Messaging
2
- VERSION = '3.4.1'.freeze
2
+ VERSION = '3.4.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: messaging
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.1
4
+ version: 3.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bukowskis
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-03 00:00:00.000000000 Z
11
+ date: 2019-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -315,10 +315,10 @@ files:
315
315
  - lib/messaging/resque_worker.rb
316
316
  - lib/messaging/routes.rb
317
317
  - lib/messaging/routing.rb
318
- - lib/messaging/routing/background_job_subscriber.rb
319
318
  - lib/messaging/routing/enqueue_message_handler.rb
319
+ - lib/messaging/routing/enqueued_route.rb
320
320
  - lib/messaging/routing/message_matcher.rb
321
- - lib/messaging/routing/subscriber.rb
321
+ - lib/messaging/routing/route.rb
322
322
  - lib/messaging/sidekiq_worker.rb
323
323
  - lib/messaging/version.rb
324
324
  - messaging.gemspec
@@ -340,8 +340,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
340
340
  - !ruby/object:Gem::Version
341
341
  version: '0'
342
342
  requirements: []
343
- rubyforge_project:
344
- rubygems_version: 2.5.1
343
+ rubygems_version: 3.0.6
345
344
  signing_key:
346
345
  specification_version: 4
347
346
  summary: A library for decoupling applications by using messaging to communicate between