Skip to content

Commit

Permalink
Merge pull request #60 from mokshaproject/py3-stomp-fixes
Browse files Browse the repository at this point in the history
Some python3 stomp fixes.
  • Loading branch information
mikebonnet committed Jun 8, 2018
2 parents 23172d6 + 06fb4bd commit 664e219
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions moksha.hub/moksha/hub/stomp/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def subscribe(self, dest, **headers):
f.headers.update(headers)
cmd = f.pack()
log.debug(cmd)
self.transport.write(cmd)
self.transport.write(cmd.encode('utf-8'))

def connectionMade(self):
""" Register with stomp server """
Expand All @@ -94,7 +94,7 @@ def connectionMade(self):
else:
cmd = stomper.connect(self.username, self.password)
log.debug(cmd)
self.transport.write(cmd)
self.transport.write(cmd.encode('utf-8'))


def ack(self, msg):
Expand All @@ -111,7 +111,7 @@ def ack(self, msg):

def dataReceived(self, data):
"""Data received, react to it and respond if needed """
self.buffer.appendData(data)
self.buffer.appendData(data.decode('utf-8'))
while True:
msg = self.buffer.getOneMessage()
if msg is None:
Expand Down Expand Up @@ -153,4 +153,4 @@ def dataReceived(self, data):
log.warn("handled=%r. Responding with %s" % (handled, response))
else:
log.debug("handled=%r. Responding with %s" % (handled, response))
self.transport.write(response)
self.transport.write(response.encode('utf-8'))
8 changes: 4 additions & 4 deletions moksha.hub/moksha/hub/stomp/stomp.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class StompHubExtension(MessagingHubExtension, ClientFactory):
def __init__(self, hub, config):
self.config = config
self.hub = hub
self._topics = hub.topics.keys()
self._topics = list(hub.topics.keys())
self._frames = []

uri = self.config.get('stomp_uri', None)
Expand Down Expand Up @@ -126,7 +126,7 @@ def connected(self, server_heartbeat):

for frame in self._frames:
log.debug('Flushing queued frame')
self.proto.transport.write(frame.pack())
self.proto.transport.write(frame.pack().encode('utf-8'))
self._frames = []

def clientConnectionLost(self, connector, reason):
Expand All @@ -152,7 +152,7 @@ def start_heartbeat(self, interval):

def heartbeat(self, interval):
if self._heartbeat_enabled:
self.proto.transport.write(chr(0x0A)) # Lub-dub
self.proto.transport.write(chr(0x0A).encode('utf-8')) # Lub-dub
reactor.callLater(interval / 1000.0, self.heartbeat, interval)
else:
log.debug("(heartbeat stopped)")
Expand All @@ -168,7 +168,7 @@ def send_message(self, topic, message, **headers):
log.info("Queueing stomp frame for later delivery")
self._frames.append(f)
else:
self.proto.transport.write(f.pack())
self.proto.transport.write(f.pack().encode('utf-8'))

super(StompHubExtension, self).send_message(topic, message, **headers)

Expand Down

0 comments on commit 664e219

Please sign in to comment.