Antti / rust-amqp

AMQP client in pure rust. Corresponds to rabbitmq spec.
MIT License
247 stars 45 forks source link

Heartbeat support? #50

Open emk opened 7 years ago

emk commented 7 years ago

Thank you for writing a great AMQP library for Rust!

I'm using this library at work, and I've run into a use-case where it would really help to have AMQP heartbeat support. Do you have any suggestions about how heartbeat support could be implemented, and where to start? Thank you for any pointers you can provide!

Antti commented 7 years ago

Hi @emk , I'm glad to hear that you find this library useful.

Heartbeat is indeed one of the missing features. It should not be that hard to implement.

  1. Make heartbeat/heartbeat interval a configuration option.
  2. Negotiate heartbeat interval with server's Tune request and send interval along with a connection::TuneOk frame.
  3. If negotiated interval is > 0, then we need to start sending heartbeats on channel 0. I guess we should start a new thread, which will do this in the specified intervals. It is only necessary to send heartbeats if there was no traffic sent through the connection during the heartbeat interval.
  4. Receive heartbeats (they should come on channel 0), and reset a heartbeat received timer. In the heartbeat thread check if heartbeat timer exceeds the heartbeat interval * 2, if so, then just close the connection (without connection.close). Somehow notify consumers/producers (?).

More information available AMQP Spec, page 36-37.

thedodd commented 6 years ago

Definitely an awesome library so far. Heartbeat support would be a great feature to implement, no doubt. I'll see if I can get around to opening a PR for this ASAP.

thedodd commented 6 years ago

Ok, opened up initial PR on getting this in order. I am giving it some practical testing now.