amqp-boilerplate 1.1.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ = version 1.1.3
2
+
3
+ * [ENHANCEMENT] Turned consumer prefetch into a global option (rverts change
4
+ in 1.1.2)
5
+
1
6
  = version 1.1.2
2
7
 
3
8
  * [FEATURE] Added amqp_channel options macro (consumer)
data/README.rdoc CHANGED
@@ -24,6 +24,7 @@ Add a initializer +amqp.rb+ to your config/initializer folder with the following
24
24
  config.on_unhandled_exception = Proc.new { |exception, consumer, metadata, payload|
25
25
  puts "Do something with exceptions: #{exception}"
26
26
  }
27
+ config.consumer_prefetch = 10
27
28
  end
28
29
 
29
30
  # Require all files that are no longer auto-loaded when Rails is in thread-safe mode
@@ -6,7 +6,6 @@ module AMQP
6
6
  # You should call the macro {.amqp_queue} method and implement {#handle_message}.
7
7
  #
8
8
  # To specify subscription options you can call the optional macro {.amqp_subscription} method.
9
- # To specify channel options you can call the optional macro {.amqp_channel} method.
10
9
  #
11
10
  # @example Basic consumer
12
11
  # class MyConsumer < AMQP::Boilerplate::Consumer
@@ -17,11 +16,10 @@ module AMQP
17
16
  # end
18
17
  # end
19
18
  #
20
- # @example Configuring subscription and channel
19
+ # @example Configuring subscription
21
20
  # class MyConsumer < AMQP::Boilerplate::Consumer
22
21
  # amqp_queue "queue.name.here", :durable => true
23
22
  # amqp_subscription :ack => true
24
- # amqp_channel :prefetch => 1
25
23
  #
26
24
  # def handle_message(payload, metadata)
27
25
  # puts "Received message: #{payload}"
@@ -57,20 +55,11 @@ module AMQP
57
55
  @subscription_options = options
58
56
  end
59
57
 
60
- # Macro that allows you to specify AMQP channel options
61
- #
62
- # @params [Hash] options Options that will be passed as options to {http://rubydoc.info/github/ruby-amqp/amqp/master/AMQP/Channel AMQP::Channel}
63
- def amqp_channel(options={})
64
- @channel_options = options
65
- end
66
-
67
58
  def start
68
59
  consumer = new
69
60
 
70
61
  channel = AMQP.channel
71
62
  channel.on_error(&consumer.method(:handle_channel_error))
72
- @channel_options ||= {}
73
- channel.prefetch(@channel_options[:prefetch]) if @channel_options[:prefetch]
74
63
 
75
64
  queue = channel.queue(@queue_name, @queue_options)
76
65
  # Binding a queue to a exchange by passing a string (instead of a AMQP::Exchange instance)
@@ -0,0 +1,14 @@
1
+ module AMQP
2
+ module Boilerplate
3
+ module ConsumerPrefetch
4
+ attr_writer :consumer_prefetch
5
+
6
+ # Wether or not to force loading consumers even if the server_type is not Passenger
7
+ #
8
+ # @see AMQP::Boilerplate.configure
9
+ def consumer_prefetch
10
+ @consumer_prefetch ||= 0
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,5 +1,5 @@
1
1
  module AMQP
2
2
  module Boilerplate
3
- VERSION = "1.1.2"
3
+ VERSION = "1.1.3"
4
4
  end
5
5
  end
@@ -4,6 +4,7 @@ require 'amqp/utilities/event_loop_helper'
4
4
  require 'amqp/boilerplate/version'
5
5
 
6
6
  require 'amqp/boilerplate/consumer'
7
+ require 'amqp/boilerplate/consumer_prefetch'
7
8
  require 'amqp/boilerplate/consumer_registry'
8
9
  require 'amqp/boilerplate/force_consumers'
9
10
  require 'amqp/boilerplate/logging'
@@ -14,6 +15,7 @@ module AMQP
14
15
  extend ConsumerRegistry
15
16
  extend Logging
16
17
  extend ForceConsumers
18
+ extend ConsumerPrefetch
17
19
 
18
20
  # Opens a channel to AMQP and starts all consumers
19
21
  #
@@ -42,7 +44,7 @@ module AMQP
42
44
  AMQP::Boilerplate.logger.info("[#{self.name}.boot] Started AMQP (Server Type: #{AMQP::Utilities::EventLoopHelper.server_type || 'unknown'})")
43
45
 
44
46
  EventMachine.next_tick do
45
- AMQP.channel ||= AMQP::Channel.new(AMQP.connection)
47
+ AMQP.channel ||= AMQP::Channel.new(AMQP.connection, AMQP::Channel.next_channel_id, :prefetch => consumer_prefetch)
46
48
 
47
49
  load_consumers
48
50
 
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe AMQP::Boilerplate::ConsumerPrefetch do
4
+ before(:each) do
5
+ AMQP::Boilerplate.stub(:logger).and_return(mock.as_null_object)
6
+ @channel = mock(AMQP::Channel)
7
+ @channel.stub(:on_error).and_return(true)
8
+ end
9
+
10
+ describe "#consumer_prefetch" do
11
+ before(:each) do
12
+ @channel_close = mock(:reply_code => "OK", :reply_text => "Something")
13
+ end
14
+
15
+ it "should be 0 by default" do
16
+ AMQP::Boilerplate.consumer_prefetch.should == 0
17
+ end
18
+ end
19
+ end
@@ -6,7 +6,6 @@ describe AMQP::Boilerplate::Consumer do
6
6
  AMQP::Boilerplate.stub(:logger).and_return(mock.as_null_object)
7
7
  @channel = mock(AMQP::Channel)
8
8
  @channel.stub(:on_error).and_return(true)
9
- @channel.stub(:prefetch).and_return(@channel)
10
9
  end
11
10
 
12
11
  describe "#handle_channel_error" do
@@ -67,12 +66,6 @@ describe AMQP::Boilerplate::Consumer do
67
66
  BarConsumer.start
68
67
  end
69
68
 
70
- it "should pass on the prefetch channel parameter" do
71
- @channel.should_receive(:prefetch).with(1).and_return(@channel)
72
- BarConsumer.start
73
- end
74
-
75
-
76
69
  it "should instantiate a consumer" do
77
70
  BarConsumer.should_receive(:new).and_return(@consumer)
78
71
  BarConsumer.start
@@ -133,6 +133,12 @@ describe AMQP::Boilerplate do
133
133
  AMQP::Boilerplate.connection_options.should == connection_options
134
134
  end
135
135
 
136
+ it "should allow us to set a prefetch value" do
137
+ prefetch = 10
138
+ AMQP::Boilerplate.configure { |config| config.consumer_prefetch = prefetch }
139
+ AMQP::Boilerplate.consumer_prefetch.should == prefetch
140
+ end
141
+
136
142
  it "should let us set a handler for uncaught exceptions" do
137
143
  on_unhandled_consumer_exception = Proc.new {}
138
144
  AMQP::Boilerplate.configure { |config| config.on_unhandled_consumer_exception = on_unhandled_consumer_exception }
data/spec/spec_helper.rb CHANGED
@@ -14,7 +14,6 @@ end
14
14
  class BarConsumer < AMQP::Boilerplate::Consumer
15
15
  amqp_queue "queue.name.here", :durable => true
16
16
  amqp_subscription :ack => true
17
- amqp_channel :prefetch => 1
18
17
  end
19
18
 
20
19
  # "Test" producers
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amqp-boilerplate
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 1
9
- - 2
10
- version: 1.1.2
9
+ - 3
10
+ version: 1.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Patrick Baselier
@@ -101,11 +101,13 @@ files:
101
101
  - lib/amqp-boilerplate.rb
102
102
  - lib/amqp/boilerplate.rb
103
103
  - lib/amqp/boilerplate/consumer.rb
104
+ - lib/amqp/boilerplate/consumer_prefetch.rb
104
105
  - lib/amqp/boilerplate/consumer_registry.rb
105
106
  - lib/amqp/boilerplate/force_consumers.rb
106
107
  - lib/amqp/boilerplate/logging.rb
107
108
  - lib/amqp/boilerplate/producer.rb
108
109
  - lib/amqp/boilerplate/version.rb
110
+ - spec/amqp/boilerplate/consumer_prefetch_spec.rb
109
111
  - spec/amqp/boilerplate/consumer_registry_spec.rb
110
112
  - spec/amqp/boilerplate/consumer_spec.rb
111
113
  - spec/amqp/boilerplate/force_consumers_spec.rb
@@ -149,6 +151,7 @@ signing_key:
149
151
  specification_version: 3
150
152
  summary: Helper modules for quickly setting up AMQP producers/consumers
151
153
  test_files:
154
+ - spec/amqp/boilerplate/consumer_prefetch_spec.rb
152
155
  - spec/amqp/boilerplate/consumer_registry_spec.rb
153
156
  - spec/amqp/boilerplate/consumer_spec.rb
154
157
  - spec/amqp/boilerplate/force_consumers_spec.rb