# Collection of code snippets by Arne Vajhøj 
# (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
import stomp
import sys

class MyListener(object):
    # receive
    def on_message(self, headers, message):
        print('|' + message + '|')

HOST = 'arnepc4'
PORT = 61613
UN = 'arne'
PW = 'topsecret'
QC2S = '/queue/QC2S'
QS2C = '/queue/QS2C'

# connect
con = stomp.Connection([(HOST, PORT)])
con.set_listener('', MyListener())
con.start()
con.connect(UN, PW)
con.subscribe(destination=QS2C, id=0, ack='auto')
# send
smsg = 'Hi from Python!'
con.send(QC2S, smsg, headers={ "amq-msg-type" : "text" })
# wait
print('Press enter to exit')
sys.stdin.read(1)
# disconnect
con.disconnect()
