amqp-boilerplate 1.1.1 → 1.1.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.
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ = version 1.1.2
2
+
3
+ * [FEATURE] Added amqp_channel options macro (consumer)
4
+
1
5
  = version 1.1.1
2
6
 
3
7
  * [ENHANCEMENT] Pass additional parameters to on_unhandled_consumer_exception
@@ -6,6 +6,7 @@ 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.
9
10
  #
10
11
  # @example Basic consumer
11
12
  # class MyConsumer < AMQP::Boilerplate::Consumer
@@ -16,10 +17,11 @@ module AMQP
16
17
  # end
17
18
  # end
18
19
  #
19
- # @example Configuring subscription
20
+ # @example Configuring subscription and channel
20
21
  # class MyConsumer < AMQP::Boilerplate::Consumer
21
22
  # amqp_queue "queue.name.here", :durable => true
22
23
  # amqp_subscription :ack => true
24
+ # amqp_channel :prefetch => 1
23
25
  #
24
26
  # def handle_message(payload, metadata)
25
27
  # puts "Received message: #{payload}"
@@ -55,11 +57,20 @@ module AMQP
55
57
  @subscription_options = options
56
58
  end
57
59
 
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
+
58
67
  def start
59
68
  consumer = new
60
69
 
61
70
  channel = AMQP.channel
62
71
  channel.on_error(&consumer.method(:handle_channel_error))
72
+ @channel_options ||= {}
73
+ channel.prefetch(@channel_options[:prefetch]) if @channel_options[:prefetch]
63
74
 
64
75
  queue = channel.queue(@queue_name, @queue_options)
65
76
  # Binding a queue to a exchange by passing a string (instead of a AMQP::Exchange instance)
@@ -1,5 +1,5 @@
1
1
  module AMQP
2
2
  module Boilerplate
3
- VERSION = "1.1.1"
3
+ VERSION = "1.1.2"
4
4
  end
5
5
  end
@@ -6,6 +6,7 @@ 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)
9
10
  end
10
11
 
11
12
  describe "#handle_channel_error" do
@@ -66,6 +67,12 @@ describe AMQP::Boilerplate::Consumer do
66
67
  BarConsumer.start
67
68
  end
68
69
 
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
+
69
76
  it "should instantiate a consumer" do
70
77
  BarConsumer.should_receive(:new).and_return(@consumer)
71
78
  BarConsumer.start
data/spec/spec_helper.rb CHANGED
@@ -14,6 +14,7 @@ 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
17
18
  end
18
19
 
19
20
  # "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: 17
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 1
9
- - 1
10
- version: 1.1.1
9
+ - 2
10
+ version: 1.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Patrick Baselier
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2012-05-08 00:00:00 +02:00
19
+ date: 2012-05-09 00:00:00 +02:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency