diff --git a/stomp/listener.py b/stomp/listener.py index f063f3f6..81d92300 100644 --- a/stomp/listener.py +++ b/stomp/listener.py @@ -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 @@ -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)) diff --git a/stomp/transport.py b/stomp/transport.py index a94f1454..30bfa1a7 100644 --- a/stomp/transport.py +++ b/stomp/transport.py @@ -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))