Simple Example

jasonrbriggs edited this page Sep 14, 2015 · 11 revisions
Clone this wiki locally

A simple example of using (assuming running a broker like Apache Apollo on the local machine with the default stomp port - 61613) is:

import time
import sys

import stomp

class MyListener(stomp.ConnectionListener):
    def on_error(self, headers, message):
        print('received an error "%s"' % message)
    def on_message(self, headers, message):
        print('received a message "%s"' % message)

conn = stomp.Connection()
conn.set_listener('', MyListener())
conn.connect('admin', 'password', wait=True)

conn.subscribe(destination='/queue/test', id=1, ack='auto')

conn.send(body=' '.join(sys.argv[1:]), destination='/queue/test')


Assuming you saved this code as "", you'd run as follows:

$ python hello world
received a message "hello world"