brontes3d-amqp 0.6.4.0 → 0.6.4.1
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/amqp.gemspec +1 -1
- data/bacon/client.rb +33 -0
- data/lib/amqp/client.rb +19 -2
- metadata +3 -2
data/amqp.gemspec
CHANGED
data/bacon/client.rb
CHANGED
@@ -197,4 +197,37 @@ describe Client do
|
|
197
197
|
["nonexistanthost", 5672], ["alsononexistant", 5672]]
|
198
198
|
end
|
199
199
|
|
200
|
+
should "handle redirect requests" do
|
201
|
+
EventMachine.stubs(:connect_server).returns(99).with do |arg1, arg2|
|
202
|
+
EM.next_tick do
|
203
|
+
@client = EM.class_eval{ @conns }[99]
|
204
|
+
@client.stubs(:send_data).returns(true)
|
205
|
+
@client.connection_completed
|
206
|
+
payload = AMQP::Protocol::Connection::Redirect.new(
|
207
|
+
:known_hosts => "nonexistanthost:5672,otherhost:5672",
|
208
|
+
:host => 'otherhost:5672')
|
209
|
+
meth = AMQP::Frame::Method.new
|
210
|
+
meth.payload = payload
|
211
|
+
@client.process_frame meth
|
212
|
+
EM.next_tick do
|
213
|
+
EM.class_eval{ @conns.delete(99) }
|
214
|
+
@client.unbind
|
215
|
+
end
|
216
|
+
end
|
217
|
+
true
|
218
|
+
end
|
219
|
+
|
220
|
+
@re_connect_args = []
|
221
|
+
EventMachine.stubs(:reconnect).returns(true).with do |arg1, arg2|
|
222
|
+
@re_connect_args << [arg1, arg2]
|
223
|
+
end
|
224
|
+
|
225
|
+
EM.next_tick{ EM.add_timer(0.5){ EM.stop_event_loop } }
|
226
|
+
|
227
|
+
AMQP.start(:host => 'nonexistanthost', :reconnect_timer => 0.1)
|
228
|
+
|
229
|
+
@re_connect_args.should == [["otherhost", 5672]]
|
230
|
+
end
|
231
|
+
|
232
|
+
|
200
233
|
end
|
data/lib/amqp/client.rb
CHANGED
@@ -35,6 +35,16 @@ module AMQP
|
|
35
35
|
when Protocol::Connection::OpenOk
|
36
36
|
succeed(self)
|
37
37
|
|
38
|
+
when Protocol::Connection::Redirect
|
39
|
+
(redir_host, redir_port) = method.host.split(":")
|
40
|
+
redir_port = redir_port.to_i #important!
|
41
|
+
STDERR.puts "Redirecting to #{redir_host}:#{redir_port}"
|
42
|
+
old_on_disconnect = @on_disconnect
|
43
|
+
@on_disconnect = Proc.new do
|
44
|
+
@on_disconnect = old_on_disconnect
|
45
|
+
reconnect true, redir_host, redir_port
|
46
|
+
end
|
47
|
+
|
38
48
|
when Protocol::Connection::Close
|
39
49
|
# raise Error, "#{method.reply_text} in #{Protocol.classes[method.class_id].methods[method.method_id]}"
|
40
50
|
STDERR.puts "#{method.reply_text} in #{Protocol.classes[method.class_id].methods[method.method_id]}"
|
@@ -161,7 +171,7 @@ module AMQP
|
|
161
171
|
}
|
162
172
|
end
|
163
173
|
|
164
|
-
def reconnect force = false
|
174
|
+
def reconnect force = false, use_host = nil, use_port = nil
|
165
175
|
if @reconnecting and not force
|
166
176
|
# wait 1 second after first reconnect attempt, in between each subsequent attempt
|
167
177
|
EM.add_timer(@settings[:reconnect_timer] || 1){ reconnect(true) }
|
@@ -181,9 +191,15 @@ module AMQP
|
|
181
191
|
|
182
192
|
log 'reconnecting'
|
183
193
|
begin
|
184
|
-
|
194
|
+
if use_host && use_port
|
195
|
+
(try_host, try_port) = [use_host, use_port]
|
196
|
+
else
|
197
|
+
(try_host, try_port) = Client.determine_reconnect_server(@settings)
|
198
|
+
STDERR.puts "Reconnecting to #{try_host}:#{try_port}"
|
199
|
+
end
|
185
200
|
EM.reconnect try_host, try_port, self
|
186
201
|
rescue RuntimeError => e
|
202
|
+
STDERR.puts "'#{e.message}' on reconnect to #{try_host}:#{try_port}"
|
187
203
|
return reconnect if e.message == "no connection"
|
188
204
|
raise e
|
189
205
|
end
|
@@ -212,6 +228,7 @@ module AMQP
|
|
212
228
|
(try_host, try_port) = determine_reconnect_server(opts)
|
213
229
|
EM.connect try_host, try_port, self, opts
|
214
230
|
rescue RuntimeError => e
|
231
|
+
STDERR.puts "'#{e.message}' on connect to #{try_host}:#{try_port}"
|
215
232
|
retry if e.message == "no connection" && @retry_count < max_retry
|
216
233
|
raise e
|
217
234
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: brontes3d-amqp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.4.
|
4
|
+
version: 0.6.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aman Gupta
|
@@ -94,6 +94,7 @@ files:
|
|
94
94
|
- bacon/client.rb
|
95
95
|
has_rdoc: true
|
96
96
|
homepage: http://amqp.rubyforge.org/
|
97
|
+
licenses:
|
97
98
|
post_install_message:
|
98
99
|
rdoc_options:
|
99
100
|
- --include=examples
|
@@ -114,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
115
|
requirements: []
|
115
116
|
|
116
117
|
rubyforge_project:
|
117
|
-
rubygems_version: 1.
|
118
|
+
rubygems_version: 1.3.5
|
118
119
|
signing_key:
|
119
120
|
specification_version: 2
|
120
121
|
summary: AMQP client implementation in Ruby/EventMachine
|