This commit is contained in:
@@ -1,37 +1,41 @@
|
||||
import logging
|
||||
|
||||
import stomp
|
||||
import json
|
||||
import time
|
||||
import msgspec
|
||||
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
|
||||
from config import get_logger
|
||||
|
||||
parser = ArgumentParser(formatter_class=ArgumentDefaultsHelpFormatter)
|
||||
parser.add_argument('--verbose', '-v', action='count', default=0)
|
||||
parser.add_argument('--config', '-c', default='kontor-docker')
|
||||
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, log):
|
||||
self.log = log
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def on_error(self, frame):
|
||||
self.log.info(f"received an error {frame.body}")
|
||||
logger.info("received an error %s", frame.body)
|
||||
|
||||
def on_message(self, frame):
|
||||
self.log.info(f"received a message '{frame.body}'")
|
||||
data = json.loads(frame.body)
|
||||
url = data['url']
|
||||
self.log.info(f"found link: {url}")
|
||||
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__':
|
||||
log = get_logger(args.verbose, args.config)
|
||||
log.info("kontor.read_queue started")
|
||||
host = [('127.0.0.1', 61616)]
|
||||
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(log))
|
||||
conn.set_listener('', MyListener())
|
||||
conn.connect(username='artemis', passcode='artemis', wait=True)
|
||||
conn.subscribe(destination='KontorMediaFile::add_link_file', id=1, ack='auto', headers={})
|
||||
conn.subscribe(destination='add_link', id=1, ack='auto', headers={})
|
||||
time.sleep(5)
|
||||
conn.disconnect()
|
||||
log.info("kontor.read_queue finished")
|
||||
|
||||
logger.info("kontor.read_queue finished")
|
||||
|
||||
Reference in New Issue
Block a user