Skip to content

Commit

Permalink
Merge pull request #113 from scop/heartbeat-send
Browse files Browse the repository at this point in the history
Don't send unnecessary heartbeats
  • Loading branch information
jasonrbriggs authored Aug 2, 2016
2 parents dc63c70 + 56b6325 commit 92da0cd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions stomp/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,16 @@ def on_heartbeat(self):

def on_send(self, frame):
"""
Add the heartbeat header to the frame when connecting.
Add the heartbeat header to the frame when connecting, and bump
next outbound heartbeat timestamp.
:param Frame frame: the Frame object
"""
if frame.cmd == CMD_CONNECT or frame.cmd == CMD_STOMP:
if self.heartbeats != (0, 0):
frame.headers[HDR_HEARTBEAT] = '%s,%s' % self.heartbeats
if self.next_outbound_heartbeat is not None:
self.next_outbound_heartbeat = monotonic() + self.send_sleep

def __update_heartbeat(self):
# Honour any grace that has been already included
Expand Down Expand Up @@ -259,8 +262,6 @@ def __heartbeat_loop(self):
now = monotonic()

if self.send_sleep != 0 and now > self.next_outbound_heartbeat:
self.next_outbound_heartbeat = now + self.send_sleep

log.debug("Sending a heartbeat message at %s", now)
try:
self.transport.transmit(utils.Frame(None, {}, None))
Expand Down
4 changes: 2 additions & 2 deletions stomp/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,9 @@ def transmit(self, frame):
packed_frame = pack(lines)

if log.isEnabledFor(logging.DEBUG):
log.debug("Sending frame %s", lines)
log.debug("Sending frame: %s", lines)
else:
log.info("Sending frame cmd=%r headers=%r", frame.cmd, frame.headers)
log.info("Sending frame: %r, headers=%r", frame.cmd or "heartbeat", frame.headers)

self.send(encode(packed_frame))

Expand Down

0 comments on commit 92da0cd

Please sign in to comment.