42 lines
1.2 KiB
Python
42 lines
1.2 KiB
Python
import logging
|
|
|
|
import stomp
|
|
import json
|
|
import time
|
|
import msgspec
|
|
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
|
|
|
|
parser = ArgumentParser(formatter_class=ArgumentDefaultsHelpFormatter)
|
|
parser.add_argument('--verbose', '-v', action='count', default=0)
|
|
parser.add_argument("--server", "-s", default="127.0.0.1")
|
|
args = parser.parse_args()
|
|
logger = logging.getLogger(__name__)
|
|
|
|
class Link(msgspec.Struct):
|
|
url: str
|
|
|
|
class MyListener(stomp.ConnectionListener):
|
|
def __init__(self):
|
|
pass
|
|
|
|
def on_error(self, frame):
|
|
logger.info("received an error %s", frame.body)
|
|
|
|
def on_message(self, frame):
|
|
logger.info("received a message %s", frame.body)
|
|
link = msgspec.json.decode(frame.body, type=Link)
|
|
self.log.info("found link: %s", link.url)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
logger.setLevel(logging.INFO)
|
|
logger.info("kontor.read_queue started")
|
|
host = [(args.server, 61616)]
|
|
conn = stomp.Connection(host_and_ports=host)
|
|
conn.set_listener('', MyListener())
|
|
conn.connect(username='artemis', passcode='artemis', wait=True)
|
|
conn.subscribe(destination='add_link', id=1, ack='auto', headers={})
|
|
time.sleep(5)
|
|
conn.disconnect()
|
|
logger.info("kontor.read_queue finished")
|