action_subscriber 4.2.2-java → 4.2.3.pre2-java
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/README.md +47 -0
- data/lib/action_subscriber/base.rb +4 -0
- data/lib/action_subscriber/bunny/subscriber.rb +3 -0
- data/lib/action_subscriber/dsl.rb +2 -1
- data/lib/action_subscriber/march_hare/subscriber.rb +3 -0
- data/lib/action_subscriber/message_retry.rb +2 -2
- data/lib/action_subscriber/router.rb +14 -14
- data/lib/action_subscriber/version.rb +1 -1
- data/spec/integration/around_filters_spec.rb +7 -0
- data/spec/lib/action_subscriber/middleware/active_record/query_cache_spec.rb +2 -1
- metadata +4 -4
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 7419ea3c3590d00bf1cc2fc3168e257582f59a20
         | 
| 4 | 
            +
              data.tar.gz: 318d18b901c32d416874d8911df5f15fabcc4cd0
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 2512db7319108875d15c0c35db248d914f404bc8ad4d0425c3080150b795558fe20461a7bdfba3dba35e87d687fdae93a11a2be1dbe95d079f40505256b05706
         | 
| 7 | 
            +
              data.tar.gz: 3aacf441a0a40205de72b4f2df3611e423d453c87f89d93c9bfdf18bc4d2c0fc6a054f6a596cbf91f3ed4db0e19fd32e08dfbeaeba99bab1917e6172c0c9e887
         | 
    
        data/README.md
    CHANGED
    
    | @@ -88,6 +88,29 @@ $ bundle exec action_subscriber start | |
| 88 88 |  | 
| 89 89 | 
             
            This will connect your subscribers to the rabbitmq broker and allow it to push messages down to your subscribers.
         | 
| 90 90 |  | 
| 91 | 
            +
            ### Around Filters
         | 
| 92 | 
            +
            "around" filters are responsible for running their associated actions by yielding, similar to how Rack middlewares work (and Rails around filters work)
         | 
| 93 | 
            +
             | 
| 94 | 
            +
            ```ruby
         | 
| 95 | 
            +
            class UserSubscriber < ::ActionSubscriber::Base
         | 
| 96 | 
            +
              around_filter :log_things
         | 
| 97 | 
            +
             | 
| 98 | 
            +
              def created
         | 
| 99 | 
            +
                # do something when a user is created
         | 
| 100 | 
            +
              end
         | 
| 101 | 
            +
             | 
| 102 | 
            +
              private
         | 
| 103 | 
            +
             | 
| 104 | 
            +
              def log_things
         | 
| 105 | 
            +
                puts "before I do some stuff"
         | 
| 106 | 
            +
                yield
         | 
| 107 | 
            +
                puts "I did some stuff"
         | 
| 108 | 
            +
              end
         | 
| 109 | 
            +
            end
         | 
| 110 | 
            +
            ```
         | 
| 111 | 
            +
             | 
| 112 | 
            +
            > Warning: an around filter will only be added once to the chain, duplicate around filters are not supported
         | 
| 113 | 
            +
             | 
| 91 114 | 
             
            Configuration
         | 
| 92 115 | 
             
            -----------------
         | 
| 93 116 | 
             
            ActionSubscriber needs to know how to connect to your rabbit server to start getting messages.
         | 
| @@ -140,6 +163,30 @@ Rabbit is told to expect message acknowledgements, but sending the acknowledgeme | |
| 140 163 | 
             
            We send the acknowledgement right after calling your subscriber.
         | 
| 141 164 | 
             
            If an error is raised your message will be retried on a sent back to rabbitmq and retried on an exponential backoff schedule.
         | 
| 142 165 |  | 
| 166 | 
            +
            ### redeliver
         | 
| 167 | 
            +
             | 
| 168 | 
            +
            A message can be sent to "redeliver" with `::ActionSubscriber::MessageRetry.redeliver_message_with_backoff` or the DSL method `redeliver` and optionally
         | 
| 169 | 
            +
            takes a "backoff schedule" which is a hash of backoff milliseconds for each redeliver, the default:
         | 
| 170 | 
            +
             | 
| 171 | 
            +
            ```ruby
         | 
| 172 | 
            +
              SCHEDULE = {
         | 
| 173 | 
            +
                2  =>        100,
         | 
| 174 | 
            +
                3  =>        500,
         | 
| 175 | 
            +
                4  =>      2_500,
         | 
| 176 | 
            +
                5  =>     12_500,
         | 
| 177 | 
            +
                6  =>     62_500,
         | 
| 178 | 
            +
                7  =>    312_500,
         | 
| 179 | 
            +
                8  =>  1_562_500,
         | 
| 180 | 
            +
                9  =>  7_812_500,
         | 
| 181 | 
            +
                10 => 39_062_500,
         | 
| 182 | 
            +
              }
         | 
| 183 | 
            +
            ```
         | 
| 184 | 
            +
             | 
| 185 | 
            +
            when the schedule "returns" `nil` the message will not be retried
         | 
| 186 | 
            +
             | 
| 187 | 
            +
            > Warning: If you use `redeliver` you need to handle reject/acknowledge according how errors are handled; if an error is caught and the
         | 
| 188 | 
            +
            > ack/reject is already done then you may duplicate the message in `at_least_once!` mode
         | 
| 189 | 
            +
             | 
| 143 190 | 
             
            Testing
         | 
| 144 191 | 
             
            -----------------
         | 
| 145 192 | 
             
            ActionSubscriber includes support for easy unit testing with RSpec.
         | 
| @@ -23,6 +23,9 @@ module ActionSubscriber | |
| 23 23 | 
             
                        logger.info "    -- routing_key: #{route.routing_key}"
         | 
| 24 24 | 
             
                        logger.info "    --    prefetch: #{route.prefetch}"
         | 
| 25 25 | 
             
                        logger.error "WARNING having a prefetch lower than your concurrency will prevent your subscriber from fully utilizing its threadpool" if route.prefetch < route.concurrency
         | 
| 26 | 
            +
                        if route.acknowledgements != subscriber.acknowledge_messages?
         | 
| 27 | 
            +
                          logger.error "WARNING subscriber has acknowledgements as #{subscriber.acknowledge_messages?} and route has acknowledgements as #{route.acknowledgements}"
         | 
| 28 | 
            +
                        end
         | 
| 26 29 | 
             
                      end
         | 
| 27 30 | 
             
                    end
         | 
| 28 31 | 
             
                  end
         | 
| @@ -23,6 +23,9 @@ module ActionSubscriber | |
| 23 23 | 
             
                        logger.info "    --       queue: #{route.queue}"
         | 
| 24 24 | 
             
                        logger.info "    -- routing_key: #{route.routing_key}"
         | 
| 25 25 | 
             
                        logger.info "    --    prefetch: #{route.prefetch} per consumer (#{route.prefetch * route.concurrency} total)"
         | 
| 26 | 
            +
                        if route.acknowledgements != subscriber.acknowledge_messages?
         | 
| 27 | 
            +
                          logger.error "WARNING subscriber has acknowledgements as #{subscriber.acknowledge_messages?} and route has acknowledgements as #{route.acknowledgements}"
         | 
| 28 | 
            +
                        end
         | 
| 26 29 | 
             
                      end
         | 
| 27 30 | 
             
                    end
         | 
| 28 31 | 
             
                  end
         | 
| @@ -12,9 +12,9 @@ module ActionSubscriber | |
| 12 12 | 
             
                  10 => 39_062_500,
         | 
| 13 13 | 
             
                }.freeze
         | 
| 14 14 |  | 
| 15 | 
            -
                def self.redeliver_message_with_backoff(env)
         | 
| 15 | 
            +
                def self.redeliver_message_with_backoff(env, backoff_schedule = SCHEDULE)
         | 
| 16 16 | 
             
                  next_attempt = get_last_attempt_number(env) + 1
         | 
| 17 | 
            -
                  ttl =  | 
| 17 | 
            +
                  ttl = backoff_schedule[next_attempt]
         | 
| 18 18 | 
             
                  return unless ttl
         | 
| 19 19 | 
             
                  retry_queue_name = "#{env.queue}.retry_#{ttl}"
         | 
| 20 20 | 
             
                  with_exchange(env, ttl, retry_queue_name) do |exchange|
         | 
| @@ -47,6 +47,20 @@ module ActionSubscriber | |
| 47 47 | 
             
                  end
         | 
| 48 48 | 
             
                end
         | 
| 49 49 |  | 
| 50 | 
            +
                def local_application_name
         | 
| 51 | 
            +
                  @_local_application_name ||= begin
         | 
| 52 | 
            +
                    local_application_name = case
         | 
| 53 | 
            +
                                             when ENV['APP_NAME'] then
         | 
| 54 | 
            +
                                               ENV['APP_NAME'].to_s.dup
         | 
| 55 | 
            +
                                             when defined?(::Rails) then
         | 
| 56 | 
            +
                                               ::Rails.application.class.parent_name.dup
         | 
| 57 | 
            +
                                             else
         | 
| 58 | 
            +
                                               raise "Define an application name (ENV['APP_NAME'])"
         | 
| 59 | 
            +
                                             end
         | 
| 60 | 
            +
                    local_application_name.downcase
         | 
| 61 | 
            +
                  end
         | 
| 62 | 
            +
                end
         | 
| 63 | 
            +
             | 
| 50 64 | 
             
                def resource_name(route_settings)
         | 
| 51 65 | 
             
                  route_settings[:subscriber].name.underscore.gsub(/_subscriber/, "").to_s
         | 
| 52 66 | 
             
                end
         | 
| @@ -61,19 +75,5 @@ module ActionSubscriber | |
| 61 75 | 
             
                def routes
         | 
| 62 76 | 
             
                  @routes ||= []
         | 
| 63 77 | 
             
                end
         | 
| 64 | 
            -
             | 
| 65 | 
            -
                def local_application_name
         | 
| 66 | 
            -
                  @_local_application_name ||= begin
         | 
| 67 | 
            -
                    local_application_name = case
         | 
| 68 | 
            -
                                             when ENV['APP_NAME'] then
         | 
| 69 | 
            -
                                               ENV['APP_NAME'].to_s.dup
         | 
| 70 | 
            -
                                             when defined?(::Rails) then
         | 
| 71 | 
            -
                                               ::Rails.application.class.parent_name.dup
         | 
| 72 | 
            -
                                             else
         | 
| 73 | 
            -
                                               raise "Define an application name (ENV['APP_NAME'])"
         | 
| 74 | 
            -
                                             end
         | 
| 75 | 
            -
                    local_application_name.downcase
         | 
| 76 | 
            -
                  end
         | 
| 77 | 
            -
                end
         | 
| 78 78 | 
             
              end
         | 
| 79 79 | 
             
            end
         | 
| @@ -1,6 +1,9 @@ | |
| 1 1 | 
             
            class InstaSubscriber < ActionSubscriber::Base
         | 
| 2 2 | 
             
              around_filter :whisper
         | 
| 3 3 | 
             
              around_filter :yell
         | 
| 4 | 
            +
              around_filter :whisper
         | 
| 5 | 
            +
              around_filter :whisper
         | 
| 6 | 
            +
              around_filter :yell
         | 
| 4 7 |  | 
| 5 8 | 
             
              def first
         | 
| 6 9 | 
             
                $messages << payload
         | 
| @@ -29,6 +32,10 @@ describe "subscriber filters", :integration => true do | |
| 29 32 | 
             
              end
         | 
| 30 33 | 
             
              let(:subscriber) { InstaSubscriber }
         | 
| 31 34 |  | 
| 35 | 
            +
              it "does not allow an around filter to be pushed on twice" do
         | 
| 36 | 
            +
                expect(InstaSubscriber.around_filters).to eq([:whisper, :yell])
         | 
| 37 | 
            +
              end
         | 
| 38 | 
            +
             | 
| 32 39 | 
             
              it "runs multiple around filters" do
         | 
| 33 40 | 
             
                $messages = []  #testing the order of things
         | 
| 34 41 | 
             
                ::ActionSubscriber.start_subscribers!
         | 
| @@ -11,7 +11,8 @@ describe ActionSubscriber::Middleware::ActiveRecord::QueryCache do | |
| 11 11 | 
             
                allow(connection).to receive(:enable_query_cache!)
         | 
| 12 12 |  | 
| 13 13 | 
             
                allow(ActiveRecord::Base).to receive(:connection).and_return(connection)
         | 
| 14 | 
            -
                 | 
| 14 | 
            +
                # Rails 5 "compat"
         | 
| 15 | 
            +
                allow(ActiveRecord::Base).to receive(:connection_id) if ::ActiveRecord::Base.respond_to?(:connection_id)
         | 
| 15 16 | 
             
              end
         | 
| 16 17 |  | 
| 17 18 | 
             
              subject { described_class.new(app) }
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: action_subscriber
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 4.2. | 
| 4 | 
            +
              version: 4.2.3.pre2
         | 
| 5 5 | 
             
            platform: java
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Brian Stien
         | 
| @@ -12,7 +12,7 @@ authors: | |
| 12 12 | 
             
            autorequire:
         | 
| 13 13 | 
             
            bindir: bin
         | 
| 14 14 | 
             
            cert_chain: []
         | 
| 15 | 
            -
            date: 2017- | 
| 15 | 
            +
            date: 2017-07-21 00:00:00.000000000 Z
         | 
| 16 16 | 
             
            dependencies:
         | 
| 17 17 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 18 18 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -276,9 +276,9 @@ required_ruby_version: !ruby/object:Gem::Requirement | |
| 276 276 | 
             
                  version: '0'
         | 
| 277 277 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 278 278 | 
             
              requirements:
         | 
| 279 | 
            -
              - - " | 
| 279 | 
            +
              - - ">"
         | 
| 280 280 | 
             
                - !ruby/object:Gem::Version
         | 
| 281 | 
            -
                  version:  | 
| 281 | 
            +
                  version: 1.3.1
         | 
| 282 282 | 
             
            requirements: []
         | 
| 283 283 | 
             
            rubyforge_project:
         | 
| 284 284 | 
             
            rubygems_version: 2.6.9
         |