Skip to content Skip to sidebar Skip to footer

Stomp.py How To Return Message From Listener

I've already read this topic: Stomp.py return message from listener But i still don't get how this works, and why there's no way to retrieve a message from the stomp object, or the

Solution 1:

Ok, I found a way myself. All you have to do, is a slight change of the listener class:

classMyListener(object):
    msg_list = []

    def__init__(self):
        self.msg_list = []

    defon_error(self, headers, message):
        self.msg_list.append('(ERROR) ' + message)

    defon_message(self, headers, message):
        self.msg_list.append(message)

And in the code, where u use stomp.py:

conn = stomp.Connection()
lst = MyListener()
conn.set_listener('', lst)
conn.start()
conn.connect()
conn.subscribe(destination='/queue/test', id=1, ack='auto')
time.sleep(2)
messages = lst.msg_list
conn.disconnect()
return render(request, 'template.html', {'messages': messages})

Post a Comment for "Stomp.py How To Return Message From Listener"