import sqlite3 from stompclient import PublishSubscribeClient logging.basicConfig(level=logging.INFO) def frame_received(frame): mid = frame.headers["message-id"] logging.info(mid) body = frame.body db = sqlite3.connect("stomp-records.sqlite") db.execute("INSERT INTO input_kills (timestamp, messageid, json) VALUES (datetime('now'), ?, ?)", (mid, body)) db.commit() db.close() logging.info("Inserted") logging.info("Starting") client = PublishSubscribeClient('eve-kill.net', 61613) listener = threading.Thread(target=client.listen_forever) listener.start() # For our example, we want to wait until the server is actually listening client.listening_event.wait() client.connect('guest', 'guest') client.subscribe("/topic/kills", frame_received) while True: time.sleep(200)
""" An example demonstrating running stompclient in subscribe-only mode. stompclient can be used without a separate listener thread if you only want to subscribe to incoming messages (and don't need to get fancy in how you handle the received frames). """ import logging import pickle logging.basicConfig(level=logging.DEBUG) logger = logging.getLogger(__name__) from stompclient import PublishSubscribeClient def frame_received(frame): # Do something with the frame! payload = pickle.loads(frame.body) logger.info("Received data: {0!r}".format(payload)) client = PublishSubscribeClient('127.0.0.1', 61613) client.connect() client.subscribe("/queue/example", frame_received) client.listen_forever()
global message71 message71.append('-- channel ' + channel + ' is not accepting answers.') else: global stat71 val = stat71[int(choice)] val = val + 1 stat71[int(choice)] = val global message71 message71.append(payload) elif channel == '72': if headers['status'] == 'Closed': global message72 message72.append('-- channel ' + channel + ' is not accepting answers.') else: global stat72 val = stat72[int(choice)] val = val + 1 stat72[int(choice)] = val global message72 message72.append(payload) #Make connection to liten to ActiveMQ client = PublishSubscribeClient('127.0.0.1', 61613) #Operate on threads so no message overlap occurs, listen forever until app closes listener = threading.Thread(target=client.listen_forever) #Start listening listener.start() #Wait till something in enqueued client.listening_event.wait() client.connect()
else: global stat71 val = stat71[int(choice)] val = val + 1 stat71[int(choice)] = val global message71 message71.append(payload) elif channel == '72': if headers['status'] == 'Closed': global message72 message72.append('-- channel ' + channel + ' is not accepting answers.') else: global stat72 val = stat72[int(choice)] val = val + 1 stat72[int(choice)] = val global message72 message72.append(payload) #Make connection to liten to ActiveMQ client = PublishSubscribeClient('127.0.0.1', 61613) #Operate on threads so no message overlap occurs, listen forever until app closes listener = threading.Thread(target=client.listen_forever) #Start listening listener.start() #Wait till something in enqueued client.listening_event.wait() client.connect()
""" import threading import logging import time import pickle logging.basicConfig(level=logging.DEBUG) logger = logging.getLogger(__name__) from stompclient import PublishSubscribeClient def frame_received(frame): # Do something with the frame! payload = pickle.loads(frame.body) logger.info("Received data: {0!r}".format(payload)) client = PublishSubscribeClient('127.0.0.1', 61613) listener = threading.Thread(target=client.listen_forever, name='Frame-Receiver') listener.start() # For our example, we want to wait until the server is actually listening client.listening_event.wait() try: result = client.connect() logger.info("Got session response from connect: {0}".format(result.session)) client.subscribe("/queue/example", frame_received) while True: time.sleep(1.0) finally: