Commit 4a45e260 authored by Fotis Paraskevopoulos's avatar Fotis Paraskevopoulos
Browse files

Updating to remove the binary parse

parent 53a91db4
Pipeline #13718 passed with stage
in 48 seconds
......@@ -12,11 +12,11 @@ class Connection:
def __init__(self, username, password,
host='localhost',
port=61613,
debug=True):
self.hosts = [(host, port)]
debug=False):
self.username = username
self.password = password
self.conn = stomp.Connection(host_and_ports=self.hosts)
self.hosts = [(host, port)]
self.conn = stomp.Connection(host_and_ports=self.hosts, auto_content_length=False)
if debug:
logging.debug("Enabling debug")
......@@ -58,11 +58,15 @@ class Connection:
def disconnect(self):
self.conn.disconnect()
def send_to_topic(self,destination, body, headers={}, **kwargs):
if not self.conn:
logging.error("Connect first")
return
self.conn.send(destination="/topic/%s" % destination,body=json.dumps(body),content_type="application/json",headers=headers, **kwargs)
str = json.dumps(body)
self.conn.send(destination="/topic/%s" % destination,
body= str,
content_type="application/json",
headers=headers, **kwargs)
from json import JSONDecodeError
from stomp.listener import ConnectionListener
import logging
......@@ -20,10 +21,6 @@ class MorphemicListener(ConnectionListener):
return headers.get('destination').replace('/topic/','')
def on(self,headers, res):
logging.debug("Unknown message %s ",res)
pass
def has_topic_name(self,headers, string):
return headers.get('destination').startswith(string)
......@@ -32,7 +29,7 @@ class MorphemicListener(ConnectionListener):
def on(self,headers, res):
logging.debug("Unknown message %s ",res)
logging.debug("Unknown message %s %s ",headers, res)
pass
def on_message(self, headers, body):
......@@ -40,10 +37,13 @@ class MorphemicListener(ConnectionListener):
logging.debug("Headers %s",headers)
logging.debug(" %s",body)
res = json.loads(body)
func_name='on_%s' % slugify(headers.get('destination').replace('/topic/',''), separator='_',)
if hasattr(self,func_name):
func = getattr(self, func_name)
func(res)
else:
self.on(headers,res)
try:
res = json.loads(body)
func_name='on_%s' % slugify(headers.get('destination').replace('/topic/',''), separator='_',)
if hasattr(self,func_name):
func = getattr(self, func_name)
func(res)
else:
self.on(headers,res)
except JSONDecodeError:
logging.error("Error decoding %s", body)
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment