# Collection of code snippets by Arne Vajhøj 
# (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import threading
import sys

import stomp

class MyListener(object):
    def __init__(self, semarg):
        self.sem = semarg
        self.sem.acquire()
    def receive(self, msg):
        self.val = msg.split('\n\n')[1]
        self.sem.release()

con = stomp.Connection('localhost', 61613)
sem = threading.Semaphore(1)
mylist = MyListener(sem)
con.addlistener(mylist)
con.start()
con.subscribe('/queue/arne')
sem.acquire()
con.unsubscribe('/queue/arne')
con.disconnect()
print mylist.val
