I recently had a task to make Python script which can read/receive and show message from ActiveMQ web console.It has classes on_message and on_error. But, unfortunately it doesn't show anything.For example, I created topic named 'topictest' as you can see from image.
Here is my code:
import time
import sys
import stomp
class ConnectionListener(object): def on_error(self, message): print('received an error %s' % message)
def on_message(self, message): print('received a message %s' % message) print(message.body) with open('/usr/ubuntu/result.txt', 'w') as txt_file: txt_file.write(str(message))
conn = stomp.Connection(host_and_ports=[('localhost', 61613)])
conn.set_listener('', ConnectionListener())
conn.connect("admin", "admin", wait=True)
conn.subscribe(destination='/topic/topictest', id='1', ack='auto')
time.sleep(2)
conn.disconnect() Reset to default