messaging 3.4.1 → 3.4.2
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 +5 -5
 - data/.circleci/config.yml +1 -1
 - data/Gemfile.lock +1 -1
 - data/lib/messaging/adapters/postgres/serialized_message.rb +1 -0
 - data/lib/messaging/base_handler.rb +1 -1
 - data/lib/messaging/rails/railtie.rb +1 -1
 - data/lib/messaging/routes.rb +2 -2
 - data/lib/messaging/routing.rb +14 -14
 - data/lib/messaging/routing/{background_job_subscriber.rb → enqueued_route.rb} +2 -2
 - data/lib/messaging/routing/message_matcher.rb +4 -18
 - data/lib/messaging/routing/{subscriber.rb → route.rb} +3 -3
 - data/lib/messaging/version.rb +1 -1
 - metadata +5 -6
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 2 
     | 
    
         
            +
            SHA256:
         
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 4e2d081991ad2e8413244571ae8c9f9d3d3d5af9ce48bfcbff424e968c1d5c18
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 8ca81941ebd45f6daad6a6c08435598a8b9f0bd3dede7fb99e9cc859a56bb6de
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: d932b1bfe5c5456e681c21280efbb055eb12acd6bcf5358dfe36d7afaca1bae61da98fbc994ea830a68c2db91230ef6883182b86d482201ae5242f38d19b3280
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 6bcf879f6c3a9f2e8353c8877c81340d64e7418b85c84a9003337927402314d4a2cc3b6d279faf25b0ba1d0209a45ef510dd9067cc23bf48cc60a1bd0ab3852c
         
     | 
    
        data/.circleci/config.yml
    CHANGED
    
    
    
        data/Gemfile.lock
    CHANGED
    
    
| 
         @@ -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( 
     | 
| 
      
 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. 
     | 
| 
      
 31 
     | 
    
         
            +
                      Messaging.routes.reload_consumer_routes!
         
     | 
| 
       32 
32 
     | 
    
         
             
                    end
         
     | 
| 
       33 
33 
     | 
    
         
             
                  end
         
     | 
| 
       34 
34 
     | 
    
         
             
                end
         
     | 
    
        data/lib/messaging/routes.rb
    CHANGED
    
    | 
         @@ -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  
     | 
| 
      
 28 
     | 
    
         
            +
                def reload_consumer_routes!
         
     | 
| 
       29 
29 
     | 
    
         
             
                  consumers.each do |c|
         
     | 
| 
       30 
     | 
    
         
            -
                    c. 
     | 
| 
      
 30 
     | 
    
         
            +
                    c.clear_routes!
         
     | 
| 
       31 
31 
     | 
    
         
             
                    consumer_definitions[c.name].fetch(:block)&.call(c)
         
     | 
| 
       32 
32 
     | 
    
         
             
                  end
         
     | 
| 
       33 
33 
     | 
    
         
             
                end
         
     | 
    
        data/lib/messaging/routing.rb
    CHANGED
    
    | 
         @@ -1,13 +1,13 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'messaging/routing/message_matcher'
         
     | 
| 
       2 
     | 
    
         
            -
            require 'messaging/routing/ 
     | 
| 
       3 
     | 
    
         
            -
            require 'messaging/routing/ 
     | 
| 
      
 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  
     | 
| 
      
 8 
     | 
    
         
            +
                # Public: Sets up routes for the events that matches the given pattern
         
     | 
| 
       9 
9 
     | 
    
         
             
                #
         
     | 
| 
       10 
     | 
    
         
            -
                # pattern  - Which messages to  
     | 
| 
      
 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 = /.*/,  
     | 
| 
       41 
     | 
    
         
            -
                   
     | 
| 
       42 
     | 
    
         
            -
                   
     | 
| 
       43 
     | 
    
         
            -
                   
     | 
| 
      
 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 
     | 
    
         
            -
                   
     | 
| 
      
 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  
     | 
| 
       54 
     | 
    
         
            -
                  @ 
     | 
| 
      
 53 
     | 
    
         
            +
                def clear_routes!
         
     | 
| 
      
 54 
     | 
    
         
            +
                  @routes = Set.new
         
     | 
| 
       55 
55 
     | 
    
         
             
                end
         
     | 
| 
       56 
56 
     | 
    
         | 
| 
       57 
57 
     | 
    
         
             
                private
         
     | 
| 
       58 
58 
     | 
    
         | 
| 
       59 
     | 
    
         
            -
                def  
     | 
| 
       60 
     | 
    
         
            -
                  @ 
     | 
| 
      
 59 
     | 
    
         
            +
                def routes
         
     | 
| 
      
 60 
     | 
    
         
            +
                  @routes ||= Set.new
         
     | 
| 
       61 
61 
     | 
    
         
             
                end
         
     | 
| 
       62 
62 
     | 
    
         | 
| 
       63 
63 
     | 
    
         
             
                def topics
         
     | 
| 
       64 
     | 
    
         
            -
                   
     | 
| 
      
 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  
     | 
| 
       5 
     | 
    
         
            -
                  def initialize(pattern,  
     | 
| 
      
 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 
     | 
| 
      
 6 
     | 
    
         
            +
                  include Dry::Equalizer(:pattern)
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
8 
     | 
    
         
             
                  attr_accessor :pattern
         
     | 
| 
       9 
     | 
    
         
            -
                  attr_accessor :topic_pattern
         
     | 
| 
       10 
9 
     | 
    
         | 
| 
       11 
     | 
    
         
            -
                  def initialize(pattern 
     | 
| 
      
 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 
     | 
    
         
            -
                     
     | 
| 
      
 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 
     | 
    
         
            -
                     
     | 
| 
      
 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  
     | 
| 
      
 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,  
     | 
| 
       13 
     | 
    
         
            -
                    @matcher = MessageMatcher.new(pattern: pattern 
     | 
| 
      
 12 
     | 
    
         
            +
                  def initialize(pattern, handler)
         
     | 
| 
      
 13 
     | 
    
         
            +
                    @matcher = MessageMatcher.new(pattern: pattern)
         
     | 
| 
       14 
14 
     | 
    
         
             
                    @handler = handler
         
     | 
| 
       15 
15 
     | 
    
         
             
                    verify_handler!
         
     | 
| 
       16 
16 
     | 
    
         
             
                  end
         
     | 
    
        data/lib/messaging/version.rb
    CHANGED
    
    
    
        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. 
     | 
| 
      
 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- 
     | 
| 
      
 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/ 
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
       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
         
     |