pwwka 0.14.0 → 0.15.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 +4 -4
- data/.travis.yml +2 -2
- data/Gemfile.lock +1 -1
- data/README.md +2 -0
- data/Rakefile +0 -10
- data/lib/pwwka/channel_connector.rb +4 -1
- data/lib/pwwka/configuration.rb +6 -0
- data/lib/pwwka/receiver.rb +4 -4
- data/lib/pwwka/tasks.rb +3 -1
- data/lib/pwwka/version.rb +1 -1
- data/owners.json +7 -0
- data/spec/unit/channel_connector_spec.rb +31 -10
- data/spec/unit/configuration_spec.rb +14 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34728502586c650b28ce76b44de9e7038ae5b980
|
4
|
+
data.tar.gz: 8732f047a559e0feae6469c1d68d0267b9537757
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0cbb4d1b802b266e087adb0726ee3878c7f939ea4a920bc0f5a8044371437e7330b085a2a7382d8e85659442880723da35e691e4639e7f42473954994a4374bc
|
7
|
+
data.tar.gz: 67259184b9333de0cdb7df54d1f1b6a223ddf569932e1b3d574afac2d64eef8ee9d6b6006db1e405ce3a0ff9a71e7b22edd98aea38d4fa8e676bdfa3b5fa55be
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -37,6 +37,7 @@ Pwwka.configure do |config|
|
|
37
37
|
config.delayed_exchange_name = "mycompany-topics-#{Rails.env}"
|
38
38
|
config.options = {allow_delayed: true}
|
39
39
|
config.requeue_on_error = true
|
40
|
+
config.default_prefetch = 10
|
40
41
|
end
|
41
42
|
```
|
42
43
|
|
@@ -211,6 +212,7 @@ It requires some environment variables to work:
|
|
211
212
|
* `HANDLER_KLASS` (required) refers to the class you have to write in your app (equivalent to a `job` in Resque)
|
212
213
|
* `QUEUE_NAME` (required) we must use named queues - see below
|
213
214
|
* `ROUTING_KEY` (optional) defaults to `#.#` (all messages)
|
215
|
+
* `PREFETCH` (optional) sets a [prefetch value](http://rubybunny.info/articles/queues.html#qos__prefetching_messages) for the subscriber
|
214
216
|
|
215
217
|
You'll also need to bring the Rake task into your app. For Rails, you'll need to edit the top-level `Rakefile`:
|
216
218
|
|
data/Rakefile
CHANGED
@@ -12,13 +12,3 @@ RSpec::Core::RakeTask.new(:spec)
|
|
12
12
|
Bundler::GemHelper.install_tasks
|
13
13
|
|
14
14
|
task default: :spec
|
15
|
-
|
16
|
-
task :tag do
|
17
|
-
require "pwwka/version"
|
18
|
-
version = "v#{Pwwka::VERSION}"
|
19
|
-
sh("git tag #{version}") { |ok,res| fail res.inspect unless ok }
|
20
|
-
sh("git push --tags origin") { |ok,res| fail res.inspect unless ok }
|
21
|
-
end
|
22
|
-
task release: [ :build, :tag ] do
|
23
|
-
sh("gem push --key rubygems_stitchfix_api_key pkg/pwwka-#{Pwwka::VERSION}.gem") { |ok,res| fail res.inspect unless ok }
|
24
|
-
end
|
@@ -8,13 +8,16 @@ module Pwwka
|
|
8
8
|
# The channel_connector starts the connection to the message_bus
|
9
9
|
# so it should only be instantiated by a method that has a strategy
|
10
10
|
# for closing the connection
|
11
|
-
def initialize
|
11
|
+
def initialize(prefetch: nil)
|
12
12
|
@configuration = Pwwka.configuration
|
13
13
|
connection_options = {automatically_recover: false}.merge(configuration.options)
|
14
14
|
@connection = Bunny.new(configuration.rabbit_mq_host,
|
15
15
|
connection_options)
|
16
16
|
@connection.start
|
17
17
|
@channel = @connection.create_channel
|
18
|
+
if prefetch
|
19
|
+
@channel.prefetch(prefetch.to_i)
|
20
|
+
end
|
18
21
|
end
|
19
22
|
|
20
23
|
def topic_exchange
|
data/lib/pwwka/configuration.rb
CHANGED
@@ -11,6 +11,7 @@ module Pwwka
|
|
11
11
|
attr_accessor :options
|
12
12
|
attr_accessor :async_job_klass
|
13
13
|
attr_accessor :send_message_resque_backoff_strategy
|
14
|
+
attr_accessor :default_prefetch
|
14
15
|
attr_reader :requeue_on_error
|
15
16
|
attr_writer :app_id
|
16
17
|
attr_writer :error_handling_chain
|
@@ -27,6 +28,7 @@ module Pwwka
|
|
27
28
|
@requeue_on_error = false
|
28
29
|
@keep_alive_on_handler_klass_exceptions = false
|
29
30
|
@async_job_klass = Pwwka::SendMessageAsyncJob
|
31
|
+
@default_prefetch = nil
|
30
32
|
end
|
31
33
|
|
32
34
|
def keep_alive_on_handler_klass_exceptions?
|
@@ -99,5 +101,9 @@ module Pwwka
|
|
99
101
|
end
|
100
102
|
end
|
101
103
|
end
|
104
|
+
|
105
|
+
def default_prefetch=(val)
|
106
|
+
@default_prefetch = val.nil? ? val : val.to_i
|
107
|
+
end
|
102
108
|
end
|
103
109
|
end
|
data/lib/pwwka/receiver.rb
CHANGED
@@ -9,17 +9,17 @@ module Pwwka
|
|
9
9
|
attr_reader :queue_name
|
10
10
|
attr_reader :routing_key
|
11
11
|
|
12
|
-
def initialize(queue_name, routing_key)
|
12
|
+
def initialize(queue_name, routing_key, prefetch: Pwwka.configuration.default_prefetch)
|
13
13
|
@queue_name = queue_name
|
14
14
|
@routing_key = routing_key
|
15
|
-
@channel_connector = ChannelConnector.new
|
15
|
+
@channel_connector = ChannelConnector.new(prefetch: prefetch)
|
16
16
|
@channel = @channel_connector.channel
|
17
17
|
@topic_exchange = @channel_connector.topic_exchange
|
18
18
|
end
|
19
19
|
|
20
|
-
def self.subscribe(handler_klass, queue_name, routing_key: "#.#", block: true)
|
20
|
+
def self.subscribe(handler_klass, queue_name, routing_key: "#.#", block: true, prefetch: Pwwka.configuration.default_prefetch)
|
21
21
|
raise "#{handler_klass.name} must respond to `handle!`" unless handler_klass.respond_to?(:handle!)
|
22
|
-
receiver = new(queue_name, routing_key)
|
22
|
+
receiver = new(queue_name, routing_key, prefetch: prefetch)
|
23
23
|
begin
|
24
24
|
info "Receiving on #{queue_name}"
|
25
25
|
receiver.topic_queue.subscribe(manual_ack: true, block: block) do |delivery_info, properties, payload|
|
data/lib/pwwka/tasks.rb
CHANGED
@@ -6,6 +6,8 @@ namespace :message_handler do
|
|
6
6
|
handler_klass = ENV['HANDLER_KLASS'].constantize
|
7
7
|
queue_name = "#{ENV['QUEUE_NAME']}_#{Rails.env}"
|
8
8
|
routing_key = ENV['ROUTING_KEY'] || "#.#"
|
9
|
-
|
9
|
+
prefetch = ENV['PREFETCH'] || Pwwka.configuration.default_prefetch
|
10
|
+
|
11
|
+
Pwwka::Receiver.subscribe(handler_klass, queue_name, routing_key: routing_key, prefetch: prefetch)
|
10
12
|
end
|
11
13
|
end
|
data/lib/pwwka/version.rb
CHANGED
data/owners.json
ADDED
@@ -4,21 +4,42 @@ require 'spec_helper.rb'
|
|
4
4
|
# by the integration tests.
|
5
5
|
describe Pwwka::ChannelConnector do
|
6
6
|
let(:bunny_session) { instance_double(Bunny::Session) }
|
7
|
+
subject(:channel_connector) { described_class.new }
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
allow(bunny_session).to receive(:start)
|
11
|
-
allow(bunny_session).to receive(:create_channel)
|
12
|
-
@default_allow_delayed = Pwwka.configuration.options[:allow_delayed]
|
13
|
-
end
|
9
|
+
describe "initialize" do
|
10
|
+
let(:bunny_channel) { instance_double(Bunny::Channel) }
|
14
11
|
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
before do
|
13
|
+
allow(Bunny).to receive(:new).and_return(bunny_session)
|
14
|
+
allow(bunny_session).to receive(:start)
|
15
|
+
allow(bunny_session).to receive(:create_channel).and_return(bunny_channel)
|
16
|
+
end
|
18
17
|
|
19
|
-
|
18
|
+
it "sets a prefetch value if configured to do so" do
|
19
|
+
expect(bunny_channel).to receive(:prefetch).with(10)
|
20
|
+
|
21
|
+
described_class.new(prefetch: 10)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "does not set a prefetch value unless configured" do
|
25
|
+
expect(bunny_channel).not_to receive(:prefetch).with(10)
|
26
|
+
|
27
|
+
described_class.new
|
28
|
+
end
|
29
|
+
end
|
20
30
|
|
21
31
|
describe "raise_if_delayed_not_allowed" do
|
32
|
+
before do
|
33
|
+
allow(Bunny).to receive(:new).and_return(bunny_session)
|
34
|
+
allow(bunny_session).to receive(:start)
|
35
|
+
allow(bunny_session).to receive(:create_channel)
|
36
|
+
@default_allow_delayed = Pwwka.configuration.options[:allow_delayed]
|
37
|
+
end
|
38
|
+
|
39
|
+
after do
|
40
|
+
Pwwka.configuration.options[:allow_delayed] = @default_allow_delayed
|
41
|
+
end
|
42
|
+
|
22
43
|
context "delayed is configured" do
|
23
44
|
it "does not blow up" do
|
24
45
|
Pwwka.configuration.options[:allow_delayed] = true
|
@@ -119,4 +119,18 @@ describe Pwwka::Configuration do
|
|
119
119
|
end
|
120
120
|
end
|
121
121
|
end
|
122
|
+
|
123
|
+
describe "#default_prefetch" do
|
124
|
+
it "is nil by default" do
|
125
|
+
expect(configuration.default_prefetch).to be_nil
|
126
|
+
end
|
127
|
+
|
128
|
+
it "is a number" do
|
129
|
+
configuration.default_prefetch = 10
|
130
|
+
expect(configuration.default_prefetch).to eq(10)
|
131
|
+
configuration.default_prefetch = "10"
|
132
|
+
expect(configuration.default_prefetch).to eq(10)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
122
136
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pwwka
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.15.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stitch Fix Engineering
|
@@ -15,7 +15,7 @@ authors:
|
|
15
15
|
autorequire:
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
|
-
date: 2017-10-
|
18
|
+
date: 2017-10-30 00:00:00.000000000 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: bunny
|
@@ -224,6 +224,7 @@ files:
|
|
224
224
|
- lib/pwwka/test_handler.rb
|
225
225
|
- lib/pwwka/transmitter.rb
|
226
226
|
- lib/pwwka/version.rb
|
227
|
+
- owners.json
|
227
228
|
- pwwka.gemspec
|
228
229
|
- spec/integration/interrupted_receivers_spec.rb
|
229
230
|
- spec/integration/send_and_receive_spec.rb
|
@@ -266,7 +267,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
266
267
|
version: '0'
|
267
268
|
requirements: []
|
268
269
|
rubyforge_project:
|
269
|
-
rubygems_version: 2.6.
|
270
|
+
rubygems_version: 2.6.14
|
270
271
|
signing_key:
|
271
272
|
specification_version: 4
|
272
273
|
summary: Send and receive messages via RabbitMQ
|