Skip to content

Commit

Permalink
Negotiate heartbeat value exactly the same way RabbitMQ Java client does
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Klishin committed Nov 21, 2012
1 parent 1de0d59 commit cd59c27
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions lib/amq/client/async/adapter.rb
Expand Up @@ -608,14 +608,13 @@ def handle_start(connection_start)
#
# @api plugin
# @see http://bit.ly/amqp091reference AMQP 0.9.1 protocol reference (Section 1.4.2.6)
def handle_tune(tune_ok)
@channel_max = tune_ok.channel_max.freeze
@frame_max = tune_ok.frame_max.freeze
@heartbeat_interval = if tune_ok.heartbeat > 0
tune_ok.heartbeat
else
@settings[:heartbeat] || @settings[:heartbeat_interval] || 0
end
def handle_tune(connection_tune)
@channel_max = connection_tune.channel_max.freeze
@frame_max = connection_tune.frame_max.freeze

client_heartbeat = @settings[:heartbeat] || @settings[:heartbeat_interval] || 0

@heartbeat_interval = negotiate_heartbeat_value(client_heartbeat, connection_tune.heartbeat)

self.send_frame(Protocol::Connection::TuneOk.encode(@channel_max, [settings[:frame_max], @frame_max].min, @heartbeat_interval))
end # handle_tune(method)
Expand Down Expand Up @@ -656,6 +655,14 @@ def handle_close_ok(close_ok)

protected

def negotiate_heartbeat_value(client_value, server_value)
if client_value == 0 || server_value == 0
[client_value, server_value].max
else
[client_value, server_value].min
end
end

# Returns next frame from buffer whenever possible
#
# @api private
Expand Down

0 comments on commit cd59c27

Please sign in to comment.