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

if !@conn.closed? @conn.disconnect => connection was forcibly closed by the remote host #110

Open georgy7 opened 9 years ago

georgy7 commented 9 years ago

How to check of connection was closed by remote host? I'm trying to make a thread, that receive stomp messages and another stuff and reconnect, when the connection is down. But I could not determine, when it is down.

!@conn.closed? => true
@conn.poll => nil (as if queue has no messages)

So, when I interrupt and try to disconnect, I got exception.

@conn.disconnect if !@conn.closed? =>
An existing connection was forcibly closed by the remote host..

I don't want to remove this exception. I want to know if connection was already closed before @conn.disconnect. Is there a way to do this?

georgy7 commented 9 years ago

I use the hash:

hash = {
  :hosts => [host],
  :reliable => false,
  :max_reconnect_attempts => 1,
  :max_reconnect_delay => 1.0,
  :start_timeout => 1.0,
  :connect_timeout => 0,
  :connread_timeout => 1.0,
  :hbser => true,
  :stompconn => true
}
@conn = Stomp::Connection.new(hash)
@conn.subscribe @stomp_destination, { :ack => 'client' }
gmallard commented 9 years ago

I am not sure there is a way to accomplish what you want with 'poll'. (At least as it is currently written.) The socket was apparently 'not ready' (or already nil).

I think you would need to actually issue 'receive' (or 'disconnect') in order to see the exception.

Sorry. I will think about this some more, and let you know if I come up with any further ideas.

Re: your connect hash ....... since you have reliable => false, those max_reconnect_xxxx parameters are ignored. Hope you know that.

You might think about reliable => true, with other appropriate parameters, which should trigger the gem to attempt to failover and/or reconnect.