Created
August 18, 2019 10:28
-
-
Save alvinhochun/940fe96c378864bb79fea7ee1466bfdd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import stomp | |
import time | |
import sys | |
import logging | |
logger = logging.getLogger('stomp.py') | |
logger.setLevel(logging.DEBUG) | |
ch = logging.StreamHandler() | |
ch.setLevel(logging.DEBUG) | |
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') | |
ch.setFormatter(formatter) | |
#logger.addHandler(ch) | |
class MyListener(stomp.ConnectionListener): | |
def on_error(self, headers, message): #What to do if an error is recieved | |
print('Error Received %s' % message) | |
def on_message(self, headers, message): #What to do if a message is recieved | |
print (message) | |
def on_disconnected(self): #What to do if the interface disconnects | |
print ("Interface Gateway Connection Lost") | |
dest='/topic/TD_ALL_SIG_AREA' #SimSig always uses this topic! | |
conn=stomp.Connection11([('127.0.0.1',51515)]) #Connect to the local server on the local port | |
conn.set_listener('test', MyListener()) | |
conn.transport.start() | |
conn.send_frame('CONNECT',headers={'accept-version':'1.1'}) | |
conn.subscribe(destination=dest, id=1, ack='auto') | |
while True: #Infinite loop to keep the program alive | |
time.sleep(1000) | |
conn.disconnect() #Close the gateway |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment