stompgem / stomp

A ruby gem for sending and receiving messages from a Stomp protocol compliant message queue. Includes: failover logic, ssl support.
http://stomp.github.com
Apache License 2.0
152 stars 80 forks source link

Automatic reconnection works only once (except for Apache Apollo) #50

Closed sahilm closed 11 years ago

sahilm commented 11 years ago
  1. I was testing out the automatic reconnection feature which should kick in if the client cannot connect to the broker.
  2. With a simple consumer like this:
require 'bundler/setup'
require 'stomp'
require 'json'
require 'pp'

hash = { :hosts => 
  [
   { :login => "admin",
     :passcode => "password",
     :host => 'localhost', 
     :port => 61613 
   }
  ],
}

client = Stomp::Client.new(hash)

# subscribe
client.subscribe("/queue/foo") do |message|
  if message.headers["content-type"] =~ /json/
    pp JSON.parse(message.body)
  else
    pp message.body
  end
end
Kernel.trap(:INT) {
  client.close
  puts "Recieved term, stopping..."
  exit 0
}
loop do
  sleep(1)
  puts "."
end

I ran the test by shutting down the broker while the consumer was running and then subsequently bringing it back up.

  1. For RabbitMQ (2.8.6.1) and ActiveMQ (5.7.0) on Mac OS X 10.8.2 and CentOS 6.3, automatic reconnection works only once. That is, the consumer reconnects the first time I bounce the broker but not on subsequent restarts.
  2. Surprisingly, automatic reconnection seems to work flawlessly with Apache Apollo (1.4) on Mac OS X 10.8.2.
sahilm commented 11 years ago

Periodically publishing to a hearbeat topic seems to trigger the reconnect logic. Tested with RabbitMQ 2.8.6.1

require 'bundler/setup'
require 'stomp'
require 'json'
require 'pp'

hash = { :hosts => 
  [
   { :login => "guest",
     :passcode => "guest",
     :host => 'localhost', 
     :port => 61613,
   }
  ]
}

client = Stomp::Client.new(hash)

client.subscribe("/queue/foo")   do |message|
  if message.headers["content-type"] =~ /json/
    pp JSON.parse(message.body)
  else
    pp message.body
  end
end

Kernel.trap(:INT) {
  client.close
  puts "Recieved term, stopping..."
  exit 0
}

loop do
  sleep 1
  begin
    client.publish("/topic/heartbeat","beat")
  rescue Stomp::Error::NoCurrentConnection => e
    puts "Retry in 1s"
    sleep 1
    retry
  end
end
gmallard commented 11 years ago

Hi - I could not recreate this here with a quickly setup test (using AMQ) on Ubuntu, however will continue to experiment a bit.

What gem version are you running?

Why does your example require 'bundler/setup? It seems unused.

What Ruby version? (Should not matter, but ....).

With AMQ are you using 'stomp://' or 'stomp+nio://'? AMQ 5.7.0 has some ragged edges when using nio.

Are your brokers on the same machine as the client?

If you could enable a call back logger (see the examples) for one of these tests, and pastebin the output that might be helpful.

Thanks, Guy

gmallard commented 11 years ago

FYI - I have not been able to recreate this in a variety of tests and environments.

Servers used: AMQ 5.7.0 and RabbitMQ 2.8.4. Both servers on Linux (Ubuntu). I did not test against Apollo, but am confident the results would be the same.

Client environments used: Ubuntu 11.10, Win 7, OSX 10.8.0.

In all these tests reconnecting at least 3 times succeeds.

One point to note: give the 'subscribe' parameters you use above, even if you do reconnect, it is likely that there will be nothing to receive from /queue/foo. You need something other than :ack => "auto" to prevent that.

sahilm commented 11 years ago

Thank you very much, Guy. I've been a tied up since the past few days. I'll be sure to follow up with more comprehensive test results and data ASAP.

gmallard commented 11 years ago

Any updates on this? Just curious ......

Thanks, Guy

gmallard commented 11 years ago

This issue report is ancient. I am going to close this, with no resolution.

Please re-open this issue including code that can reproduce the problem when you have developed that code.

pic commented 11 years ago

I'm experiencing the same with AMQ 5.5.1 . Gem version is 1.2.8 I can constantly reproduce the problem with these steps:

I can provide more info, I can test with AMQ 5.7.0 too, please let me know

pic commented 11 years ago

same behaviour with AMQ 5.7.0

gmallard commented 11 years ago

Thanks. With your description, this can actually be recreated. Reopened.

pic commented 11 years ago

thanks to you, tell me if you need more info

gmallard commented 11 years ago

Thanks for the hint about utils.rb, line 100. That was being masked in previous attempts to recreate this.

Closed: 3198504