Failover client does not work with subscriptions
mconigliaro opened this issue · 5 comments
Hello,
I'm currently testing the failover client with the code below. I simply start two brokers on different ports and take turns stopping and restarting each one. What I find is that frames do get retransmitted to an available broker, but subscriptions seem to be locked to the original broker. Essentially, the failover stuff does not seem to be working at all with subscriptions. Am I doing something wrong?
Note that although my brokers are running on different ports, I had to use two different hosts (i.e. 'localhost' and '127.0.0.1') in order to see which broker the client was currently working with. I could not find a method/attribute on client.active_client that would return the port number (even the uri method omitted the port number). I'm not sure if this is a bug, or if I'm missing something here too.
#!/usr/bin/env ruby
require 'onstomp'
require 'onstomp/failover'
uris = [
'stomp://admin:password@localhost:61613',
'stomp://admin:password@127.0.0.1:62613'
]
client = OnStomp::Failover::Client.new(uris).connect
client.retry_attempts = -1
client.retry_delay = 1
client.subscribe("/queue/test") do |msg|
puts "#{client.active_client.host} << #{msg.body}"
end
i = 0
loop do
client.send("/queue/test", (i += 1).to_s) do |r|
puts "#{client.active_client.host} >> #{i}"
end
sleep 1
end
I'll have some time this weekend to dig into this and resolve the issue. Note that the failover extension is still experimental at this time.
As for the host
and port
issue, OnStomp::Client#host
is provided for STOMP 1.1, which allows for potential virtual hosts, similar to HTTP's Host
header, and can be configured independently of the actual hostname of the provided URI. By default, the URI's hostname is used. Examining the OnStomp::Client#uri
property is probably the better way to go for what you are after.
For the record, OnStomp::Client#uri
only returns "failover:()". I was hoping for a property that would tell me the URI of the OnStomp::Client#active_client
. I tried client.active_client.uri
, but that URI omits the port for some reason.
What Ruby platform and version are you running? client.active_client.uri
should have its port
property set.
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.3.0]