amqp-boilerplate 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +9 -0
- data/README.rdoc +1 -0
- data/lib/amqp/boilerplate.rb +11 -0
- data/lib/amqp/boilerplate/consumer.rb +7 -9
- data/lib/amqp/boilerplate/version.rb +1 -1
- data/spec/amqp/boilerplate/consumer_spec.rb +12 -10
- data/spec/amqp/boilerplate_spec.rb +6 -0
- metadata +11 -10
data/CHANGELOG
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
= version 1.1.0
|
2
|
+
|
3
|
+
* [FEATURE] Added on_unhandled_consumer_exception option to allow for more
|
4
|
+
flexible exception handling (consumer exceptions)
|
5
|
+
|
6
|
+
= version 1.0.0
|
7
|
+
|
8
|
+
First stable release
|
9
|
+
|
1
10
|
= version 0.0.8
|
2
11
|
|
3
12
|
* [FEATURE] Do not start consumers when server type is unknown
|
data/README.rdoc
CHANGED
@@ -21,6 +21,7 @@ Add a initializer +amqp.rb+ to your config/initializer folder with the following
|
|
21
21
|
config.logger = ::Rails.logger
|
22
22
|
config.consumer_paths += %W( #{Rails.root}/app/consumers )
|
23
23
|
config.connection_options = { :host => "localhost", :port => 5672, :vhost => Rails.env }
|
24
|
+
config.on_unhandled_exception = Proc.new { |exception| puts "Do something with exceptions: #{exception}" }
|
24
25
|
end
|
25
26
|
|
26
27
|
# Require all files that are no longer auto-loaded when Rails is in thread-safe mode
|
data/lib/amqp/boilerplate.rb
CHANGED
@@ -61,6 +61,7 @@ module AMQP
|
|
61
61
|
# config.logger = ::Rails.logger
|
62
62
|
# config.consumer_paths += %W( #{Rails.root}/app/consumers )
|
63
63
|
# config.connection_options = { :host => "localhost", :port => 5672, :vhost => Rails.env }
|
64
|
+
# config.on_unhandled_exception = Proc.new { |exception| puts "Do something with exceptions: #{exception}" }
|
64
65
|
# end
|
65
66
|
def self.configure
|
66
67
|
yield self if block_given?
|
@@ -77,6 +78,16 @@ module AMQP
|
|
77
78
|
@connection_options = options
|
78
79
|
end
|
79
80
|
|
81
|
+
def self.on_unhandled_consumer_exception
|
82
|
+
@on_unhandled_consumer_exception
|
83
|
+
end
|
84
|
+
|
85
|
+
# Pass a +Proc+ object to this option that will function as a handler for
|
86
|
+
# uncaught exceptions in a consumer.
|
87
|
+
def self.on_unhandled_consumer_exception=(handler)
|
88
|
+
@on_unhandled_consumer_exception = handler
|
89
|
+
end
|
90
|
+
|
80
91
|
def self.start
|
81
92
|
AMQP.start self.connection_options
|
82
93
|
end
|
@@ -88,16 +88,14 @@ module AMQP
|
|
88
88
|
def handle_message_wrapper(metadata, payload)
|
89
89
|
AMQP::Boilerplate.logger.debug("[#{self.class}#handle_message_wrapper] Received message: #{payload}")
|
90
90
|
handle_message(metadata, payload)
|
91
|
-
rescue
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
MSG
|
98
|
-
|
99
|
-
AMQP::Boilerplate.logger.error(message)
|
91
|
+
rescue Exception => e
|
92
|
+
if AMQP::Boilerplate.on_unhandled_consumer_exception.is_a?(Proc)
|
93
|
+
AMQP::Boilerplate.on_unhandled_consumer_exception.call(e)
|
94
|
+
else
|
95
|
+
raise e
|
96
|
+
end
|
100
97
|
end
|
98
|
+
|
101
99
|
end
|
102
100
|
end
|
103
101
|
end
|
@@ -144,32 +144,34 @@ describe AMQP::Boilerplate::Consumer do
|
|
144
144
|
@consumer.handle_message_wrapper(@metadata, @payload)
|
145
145
|
end
|
146
146
|
|
147
|
-
|
148
|
-
before
|
149
|
-
|
147
|
+
context "when on_unhandled_consumer_exception option set" do
|
148
|
+
before do
|
149
|
+
AMQP::Boilerplate.stub(:on_unhandled_consumer_exception).and_return(Proc.new { |e|
|
150
|
+
AMQP::Boilerplate.logger.error("foo: #{e.message}")
|
151
|
+
})
|
150
152
|
end
|
151
153
|
|
152
|
-
it "should
|
154
|
+
it "should not raise the exception" do
|
153
155
|
expect {
|
154
156
|
@consumer.handle_message_wrapper(@metadata, @payload)
|
155
157
|
}.to_not raise_error
|
156
158
|
end
|
157
159
|
|
158
|
-
it "should
|
160
|
+
it "should yield the on_unhandled_consumer_exception" do
|
159
161
|
AMQP::Boilerplate.logger.should_receive(:error)
|
160
162
|
@consumer.handle_message_wrapper(@metadata, @payload)
|
161
163
|
end
|
162
164
|
end
|
163
165
|
|
164
|
-
|
165
|
-
before
|
166
|
-
|
166
|
+
context "when on_unhandled_consumer_exception option set" do
|
167
|
+
before do
|
168
|
+
AMQP::Boilerplate.stub(:on_unhandled_consumer_exception).and_return(nil)
|
167
169
|
end
|
168
170
|
|
169
|
-
it "should
|
171
|
+
it "should re-raise the exception" do
|
170
172
|
expect {
|
171
173
|
@consumer.handle_message_wrapper(@metadata, @payload)
|
172
|
-
}.to raise_error
|
174
|
+
}.to raise_error
|
173
175
|
end
|
174
176
|
end
|
175
177
|
end
|
@@ -132,6 +132,12 @@ describe AMQP::Boilerplate do
|
|
132
132
|
AMQP::Boilerplate.configure { |config| config.connection_options = connection_options }
|
133
133
|
AMQP::Boilerplate.connection_options.should == connection_options
|
134
134
|
end
|
135
|
+
|
136
|
+
it "should let us set a handler for uncaught exceptions" do
|
137
|
+
on_unhandled_consumer_exception = Proc.new {}
|
138
|
+
AMQP::Boilerplate.configure { |config| config.on_unhandled_consumer_exception = on_unhandled_consumer_exception }
|
139
|
+
AMQP::Boilerplate.on_unhandled_consumer_exception.should == on_unhandled_consumer_exception
|
140
|
+
end
|
135
141
|
end
|
136
142
|
|
137
143
|
describe ".start" do
|
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:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 1.0.0
|
10
|
+
version: 1.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Patrick Baselier
|
@@ -16,10 +16,12 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2012-
|
19
|
+
date: 2012-05-08 00:00:00 +02:00
|
20
|
+
default_executable:
|
20
21
|
dependencies:
|
21
22
|
- !ruby/object:Gem::Dependency
|
22
23
|
name: rake
|
24
|
+
prerelease: false
|
23
25
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|
24
26
|
none: false
|
25
27
|
requirements:
|
@@ -31,10 +33,10 @@ dependencies:
|
|
31
33
|
- 9
|
32
34
|
version: "0.9"
|
33
35
|
type: :development
|
34
|
-
prerelease: false
|
35
36
|
requirement: *id001
|
36
37
|
- !ruby/object:Gem::Dependency
|
37
38
|
name: rspec
|
39
|
+
prerelease: false
|
38
40
|
version_requirements: &id002 !ruby/object:Gem::Requirement
|
39
41
|
none: false
|
40
42
|
requirements:
|
@@ -46,10 +48,10 @@ dependencies:
|
|
46
48
|
- 6
|
47
49
|
version: "2.6"
|
48
50
|
type: :development
|
49
|
-
prerelease: false
|
50
51
|
requirement: *id002
|
51
52
|
- !ruby/object:Gem::Dependency
|
52
53
|
name: yard
|
54
|
+
prerelease: false
|
53
55
|
version_requirements: &id003 !ruby/object:Gem::Requirement
|
54
56
|
none: false
|
55
57
|
requirements:
|
@@ -61,10 +63,10 @@ dependencies:
|
|
61
63
|
- 7
|
62
64
|
version: "0.7"
|
63
65
|
type: :development
|
64
|
-
prerelease: false
|
65
66
|
requirement: *id003
|
66
67
|
- !ruby/object:Gem::Dependency
|
67
68
|
name: amqp
|
69
|
+
prerelease: false
|
68
70
|
version_requirements: &id004 !ruby/object:Gem::Requirement
|
69
71
|
none: false
|
70
72
|
requirements:
|
@@ -76,7 +78,6 @@ dependencies:
|
|
76
78
|
- 8
|
77
79
|
version: "0.8"
|
78
80
|
type: :runtime
|
79
|
-
prerelease: false
|
80
81
|
requirement: *id004
|
81
82
|
description: Collection of modules that aid in setting up AMQP producers and consumers.
|
82
83
|
email:
|
@@ -113,6 +114,7 @@ files:
|
|
113
114
|
- spec/amqp/boilerplate_spec.rb
|
114
115
|
- spec/fixtures/consumers/dummy_consumer.rb
|
115
116
|
- spec/spec_helper.rb
|
117
|
+
has_rdoc: true
|
116
118
|
homepage: ""
|
117
119
|
licenses: []
|
118
120
|
|
@@ -142,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
144
|
requirements: []
|
143
145
|
|
144
146
|
rubyforge_project: amqp-boilerplate
|
145
|
-
rubygems_version: 1.
|
147
|
+
rubygems_version: 1.6.2
|
146
148
|
signing_key:
|
147
149
|
specification_version: 3
|
148
150
|
summary: Helper modules for quickly setting up AMQP producers/consumers
|
@@ -155,4 +157,3 @@ test_files:
|
|
155
157
|
- spec/amqp/boilerplate_spec.rb
|
156
158
|
- spec/fixtures/consumers/dummy_consumer.rb
|
157
159
|
- spec/spec_helper.rb
|
158
|
-
has_rdoc:
|