amqp-boilerplate 1.1.4 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +5 -1
- data/lib/amqp/boilerplate.rb +19 -0
- data/lib/amqp/boilerplate/producer.rb +7 -4
- data/lib/amqp/boilerplate/version.rb +1 -1
- data/spec/amqp/boilerplate/producer_spec.rb +8 -1
- data/spec/amqp/boilerplate_spec.rb +24 -1
- metadata +5 -5
data/CHANGELOG
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
= version 1.2.0
|
2
|
+
|
3
|
+
* [FEATURE] Added shutdown method that stops AMQP and EventMachine loop
|
4
|
+
|
1
5
|
= version 1.1.4
|
2
6
|
|
3
7
|
* [BUG] Prefetch option was not actually honored. Now it is :)
|
@@ -5,7 +9,7 @@
|
|
5
9
|
= version 1.1.3
|
6
10
|
|
7
11
|
* [ENHANCEMENT] Turned consumer prefetch into a global option (rverts change
|
8
|
-
|
12
|
+
in 1.1.2)
|
9
13
|
|
10
14
|
= version 1.1.2
|
11
15
|
|
data/lib/amqp/boilerplate.rb
CHANGED
@@ -49,6 +49,7 @@ module AMQP
|
|
49
49
|
load_consumers
|
50
50
|
|
51
51
|
if AMQP::Utilities::EventLoopHelper.server_type || force_consumers
|
52
|
+
AMQP::Boilerplate.logger.debug("[#{self.name}.boot] Starting consumers")
|
52
53
|
start_consumers
|
53
54
|
else
|
54
55
|
AMQP::Boilerplate.logger.debug("[#{self.name}.boot] Unknown server type, not starting consumers")
|
@@ -56,6 +57,24 @@ module AMQP
|
|
56
57
|
end
|
57
58
|
end
|
58
59
|
|
60
|
+
# Try to gracefully close channel and stop EventMachine
|
61
|
+
#
|
62
|
+
# TODO Close all open channels and not just the default one
|
63
|
+
#
|
64
|
+
# @return [void]
|
65
|
+
def self.shutdown
|
66
|
+
AMQP.stop do
|
67
|
+
AMQP::Boilerplate.logger.debug("[#{self.name}.shutdown] Attempting graceful channel and EventMachine shutdown")
|
68
|
+
EventMachine.stop
|
69
|
+
end
|
70
|
+
|
71
|
+
# 5 seconds is an arbitrary delay
|
72
|
+
EventMachine::Timer.new(5) do
|
73
|
+
AMQP::Boilerplate.logger.debug("[#{self.name}.shutdown] Graceful shutdown of EM didn't work, forcing shutdown")
|
74
|
+
EventMachine.stop
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
59
78
|
# Configures AMQP::Boilerplate and yields AMQP::Boilerplate object to the block
|
60
79
|
#
|
61
80
|
# @example
|
@@ -92,12 +92,15 @@ module AMQP
|
|
92
92
|
#
|
93
93
|
# @see AMQP::Exchange#publish
|
94
94
|
# @return [void]
|
95
|
-
def publish
|
95
|
+
def publish(&block)
|
96
|
+
block ||= lambda {
|
97
|
+
AMQP::Boilerplate.logger.debug "[#{self.class}] Message was published"
|
98
|
+
}
|
99
|
+
|
96
100
|
message = send(self.class.amqp_boilerplate_message.to_sym)
|
97
101
|
if message
|
98
|
-
|
99
|
-
|
100
|
-
end
|
102
|
+
AMQP::Boilerplate.logger.debug "[#{self.class}] Publishing message:\n#{message}"
|
103
|
+
exchange.publish(message, self.class.amqp_boilerplate_options, &block)
|
101
104
|
else
|
102
105
|
AMQP::Boilerplate.logger.debug "[#{self.class}] Not publishing nil message"
|
103
106
|
end
|
@@ -82,8 +82,15 @@ describe AMQP::Boilerplate::Producer do
|
|
82
82
|
end
|
83
83
|
|
84
84
|
it "should log after delivering message" do
|
85
|
-
AMQP::Boilerplate.logger.should_receive(:debug).with("[#{@producer.class}]
|
85
|
+
AMQP::Boilerplate.logger.should_receive(:debug).with("[#{@producer.class}] Message was published")
|
86
86
|
@producer.publish
|
87
87
|
end
|
88
|
+
|
89
|
+
it "should yield to custom block when given" do
|
90
|
+
AMQP::Boilerplate.logger.should_receive(:debug).with("Custom block")
|
91
|
+
@producer.publish do
|
92
|
+
AMQP::Boilerplate.logger.debug("Custom block")
|
93
|
+
end
|
94
|
+
end
|
88
95
|
end
|
89
96
|
end
|
@@ -49,7 +49,6 @@ describe AMQP::Boilerplate do
|
|
49
49
|
AMQP::Boilerplate.boot
|
50
50
|
end
|
51
51
|
|
52
|
-
|
53
52
|
it "should log server type as 'unknown'" do
|
54
53
|
AMQP::Boilerplate.logger.should_receive(:info).with(/Server Type: unknown/)
|
55
54
|
AMQP::Boilerplate.boot
|
@@ -110,6 +109,30 @@ describe AMQP::Boilerplate do
|
|
110
109
|
end
|
111
110
|
end
|
112
111
|
|
112
|
+
describe ".shutdown" do
|
113
|
+
subject { described_class.shutdown }
|
114
|
+
|
115
|
+
before do
|
116
|
+
EventMachine::Timer.stub(:new).and_yield
|
117
|
+
EventMachine.stub(:stop)
|
118
|
+
end
|
119
|
+
|
120
|
+
it "closes AMQP connection" do
|
121
|
+
AMQP.should_receive(:stop)
|
122
|
+
subject
|
123
|
+
end
|
124
|
+
|
125
|
+
it "stops EventMachine" do
|
126
|
+
EventMachine.should_receive(:stop)
|
127
|
+
subject
|
128
|
+
end
|
129
|
+
|
130
|
+
it "sets a one-off timer to make sure event loop shuts down" do
|
131
|
+
EventMachine::Timer.should_receive(:new)
|
132
|
+
subject
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
113
136
|
describe ".configure" do
|
114
137
|
after(:each) do
|
115
138
|
AMQP::Boilerplate.logger = nil
|
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: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 1.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 1.2.0
|
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
|
19
|
+
date: 2012-06-05 00:00:00 +02:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|