mirror of
https://github.com/EDCD/EDDN.git
synced 2025-06-20 08:43:55 +03:00
Added topic in Gateway/Relay to allow filtering
This commit is contained in:
parent
02bf4d8c35
commit
c7187e90bd
@ -45,7 +45,7 @@ def configure():
|
|||||||
validator.addSchemaResource(schemaRef, os.path.dirname(__file__) + '/' + schemaFile)
|
validator.addSchemaResource(schemaRef, os.path.dirname(__file__) + '/' + schemaFile)
|
||||||
|
|
||||||
|
|
||||||
def push_message(string_message):
|
def push_message(string_message, topic):
|
||||||
"""
|
"""
|
||||||
Spawned as a greenlet to push messages (strings) through ZeroMQ.
|
Spawned as a greenlet to push messages (strings) through ZeroMQ.
|
||||||
This is a dumb method that just pushes strings; it assumes you've already validated
|
This is a dumb method that just pushes strings; it assumes you've already validated
|
||||||
@ -53,9 +53,9 @@ def push_message(string_message):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# Push a zlib compressed JSON representation of the message to
|
# Push a zlib compressed JSON representation of the message to
|
||||||
# announcers.
|
# announcers with schema as topic
|
||||||
compressed_msg = zlib.compress(string_message)
|
compressed_msg = zlib.compress(string_message)
|
||||||
sender.send(compressed_msg)
|
sender.send("%s |-| %s" % (topic, compressed_msg))
|
||||||
statsCollector.tally("outbound")
|
statsCollector.tally("outbound")
|
||||||
|
|
||||||
|
|
||||||
@ -142,7 +142,7 @@ def parse_and_error_handle(data):
|
|||||||
|
|
||||||
# Sends the parsed MarketOrderList or MarketHistoryList to the Announcers
|
# Sends the parsed MarketOrderList or MarketHistoryList to the Announcers
|
||||||
# as compressed JSON.
|
# as compressed JSON.
|
||||||
gevent.spawn(push_message, simplejson.dumps(parsed_message))
|
gevent.spawn(push_message, (simplejson.dumps(parsed_message), parsed_message['$schemaRef']))
|
||||||
logger.info("Accepted %s upload from %s" % (
|
logger.info("Accepted %s upload from %s" % (
|
||||||
parsed_message, get_remote_address()
|
parsed_message, get_remote_address()
|
||||||
))
|
))
|
||||||
|
@ -42,12 +42,23 @@ class Relay(Thread):
|
|||||||
context = zmq.Context()
|
context = zmq.Context()
|
||||||
|
|
||||||
receiver = context.socket(zmq.SUB)
|
receiver = context.socket(zmq.SUB)
|
||||||
|
|
||||||
|
# Filters on topics or not...
|
||||||
|
if Settings.RELAY_RECEIVE_ONLY_GATEWAY_EXTRA_JSON == True:
|
||||||
|
for schemaRef, schemaFile in Settings.GATEWAY_JSON_SCHEMAS.iteritems():
|
||||||
|
receiver.setsockopt(zmq.SUBSCRIBE, schemaRef)
|
||||||
|
for schemaRef, schemaFile in Settings.RELAY_EXTRA_JSON_SCHEMAS.iteritems():
|
||||||
|
receiver.setsockopt(zmq.SUBSCRIBE, schemaRef)
|
||||||
|
else:
|
||||||
receiver.setsockopt(zmq.SUBSCRIBE, '')
|
receiver.setsockopt(zmq.SUBSCRIBE, '')
|
||||||
|
|
||||||
|
|
||||||
for binding in Settings.RELAY_RECEIVER_BINDINGS:
|
for binding in Settings.RELAY_RECEIVER_BINDINGS:
|
||||||
# Relays bind upstream to an Announcer, or another Relay.
|
# Relays bind upstream to an Announcer, or another Relay.
|
||||||
receiver.connect(binding)
|
receiver.connect(binding)
|
||||||
|
|
||||||
sender = context.socket(zmq.PUB)
|
sender = context.socket(zmq.PUB)
|
||||||
|
|
||||||
for binding in Settings.RELAY_SENDER_BINDINGS:
|
for binding in Settings.RELAY_SENDER_BINDINGS:
|
||||||
# End users, or other relays, may attach here.
|
# End users, or other relays, may attach here.
|
||||||
sender.bind(binding)
|
sender.bind(binding)
|
||||||
@ -58,6 +69,15 @@ class Relay(Thread):
|
|||||||
to any subscribers.
|
to any subscribers.
|
||||||
:param str message: A JSON string to re-broadcast.
|
:param str message: A JSON string to re-broadcast.
|
||||||
"""
|
"""
|
||||||
|
# Separate topic from message
|
||||||
|
message = message.split(' |-| ')
|
||||||
|
|
||||||
|
# Handle gateway not sending topic
|
||||||
|
if len(message) > 1:
|
||||||
|
message = message[1]
|
||||||
|
else:
|
||||||
|
message = message[0]
|
||||||
|
|
||||||
# if is_message_duped(message):
|
# if is_message_duped(message):
|
||||||
# We've already seen this message recently. Discard it.
|
# We've already seen this message recently. Discard it.
|
||||||
# return
|
# return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user