import asyncio
import json
import logging
+import re
import zlib
import zmq
import zmq.asyncio
log = logging.getLogger('eddn')
-url = 'tcp://eddn-relay.elite-markets.net:9500'
-topic = b''
+url = 'tcp://eddn-gateway.elite-markets.net:9500'
+schema_prefix = 'http://schemas.elite-markets.net/eddn'
+topics = ['{}/{}/{}'.format(schema_prefix, 'journal', 1)]
timeout = 600000
async def listen(plugins):
while True:
try:
subscriber = context.socket(zmq.SUB)
+ log.info('Connecting to {}'.format(url))
subscriber.connect(url)
- subscriber.setsockopt(zmq.SUBSCRIBE, topic)
+ if len(topics):
+ for topic in topics:
+ log.info('Subscribing to {}'.format(topic))
+ subscriber.setsockopt(zmq.SUBSCRIBE, topic.encode('utf-8'))
+ else:
+ subscriber.setsockopt(zmq.SUBSCRIBE, b'')
subscriber.setsockopt(zmq.RCVTIMEO, timeout)
poller = zmq.asyncio.Poller()
poller.register(subscriber, zmq.POLLOUT)
except ValueError:
log.exception('Malformed JSON in message')
return None
+
+def is_schema(schema, namespace, *, version = None, test = False):
+ regex = '^{}/{}/{}{}$'.format(schema_prefix, namespace, version if version is not None else '\d+', '/test' if test else '').encode('string-escape')
+ return bool(re.match(regex, schema))