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 reconnect not working Apache ActiveMQ 5.6.0 #58

Closed david-mccullars closed 11 years ago

david-mccullars commented 11 years ago

To isolate I wrote a little test subscriber:

client = Stomp::Client.open("stomp://localhost:61613")
client.subscribe('/queue/testme') do |msg|
  puts msg.body
end
client.join

When run it will correctly consume each method until ActiveMQ is restarted. When that happens the client will enter a state where it is still running but no longer has an active subscription (confirmed in the AMQ admin console), nor will it consume any further messages.

In verion 1.2.5 of the gem, the AMQ restart would trigger a nil exception which would crash the program. Although a crash is generally bad, in this case it is preferable as at least the consumer hasn't entered a zombie-like state where it will never do anything useful again.

gmallard commented 11 years ago

First: upgrade the gem please. Current is 1.2.10. You are way behind.

That will not solve the "problem" you show. The behavior you describe is expected with that connection URL. Because the "reliable" property defaults to false. If "reliable" is false, retries (reconnects) will never happen.

Please see the README file, particularly the section with "this is the recommended login technique" regarding hash logins.

So, ... an example .....

require 'stomp'
hash = { :hosts => [ 
       {:login => 'guest', :passcode => 'guest', :host => 'localhost', :port => 61613, :ssl => false}, # AMQ
      ],
      :reliable => true,
    }
client = Stomp::Client.open(hash)
client.subscribe('/queue/testme') do |msg|
  puts msg.body
end
client.join

Also: Personal opinion is that you need to upgrade AMQ. We only test with 5.8.0 currently.

gmallard commented 11 years ago

I thought about this over night.

With the URL you are using, the connection should crash, not just hang. It should not however crash with:

lib/client/utils.rb:102:in `block in start_listeners': undefined method `command' for nil:NilClass (NoMethodError)

I'll accept this as a bug.

But if you want true retries, please follow my previous suggestion about using a login hash and :reliable => true.

FWIW, the hang you are seeing was introduced by commit 3198504 (between versions 1.2.8 and 1.2.9) which was a fix for issue #50.

gmallard commented 11 years ago

Fixed by 4c1d2f1. This will be in the next release, or can be obtained from the current repository.

When a client's listener thread receives a nil message (EOF) and the underlying connection is not reliable, a valid STOMP error will be raised:

Stomp::Error::NilMessageError
david-mccullars commented 11 years ago

Thanks for the speedy reply and fix!

(And sorry for the confusion over version. As I'm sure you've figured out, the original issue was made against the latest release 1.2.10. We were trying to upgrade from 1.2.5 to 1.2.10, but this issue prevented us from doing so.)

gmallard commented 11 years ago

Yeah, I did finally figure out that you were actually trying to upgrade.

Another plug for using hashed logins: you can actually then use the STOMP 1.1 protocol level, and as part of that use the heartbeat mechanisms. As of 1.2.10 failovers can be initiated from the threads that handle heartbeats if requested. See the "notes' install directory for advice on using this.