Skeletal but functional system.

Gateway just pumps messages into zmq to a Relay, Client parses them as
JSON and spits them out.
This commit is contained in:
James Muscat committed 2014-11-15 17:12:23 +00:00
1 parent bffa6b3a13
commit 445c92c1b2
3 files changed
+110 -2

No files matched your search

+21
View File
@@ -0,0 +1,21 @@
import zlib
import zmq.green as zmq
import simplejson
import sys
def main():
context = zmq.Context()
subscriber = context.socket(zmq.SUB)
subscriber.connect('tcp://localhost:9500')
subscriber.setsockopt(zmq.SUBSCRIBE, "")
while True:
market_json = zlib.decompress(subscriber.recv())
market_data = simplejson.loads(market_json)
print market_data
sys.stdout.flush()
if __name__ == '__main__':
main()
+39
View File
@@ -0,0 +1,39 @@
"""
Contains the necessary ZeroMQ socket and a helper function to publish
market data to the Announcer daemons.
"""
import logging
import zlib
import zmq.green as zmq
from eddn.conf import Settings
logger = logging.getLogger(__name__)
# This socket is used to push market data out to the Announcers over ZeroMQ.
context = zmq.Context()
sender = context.socket(zmq.PUB)
# Get the list of transports to bind from settings. This allows us to PUB
# messages to multiple announcers over a variety of socket types
# (UNIX sockets and/or TCP sockets).
for binding in Settings.GATEWAY_SENDER_BINDINGS:
sender.bind(binding)
def push_message(parsed_message):
"""
Spawned as a greenlet to push parsed messages through ZeroMQ.
"""
#===========================================================================
# try:
# # This will be the representation to send to the Announcers.
# json_str = unified.encode_to_json(parsed_message)
# except TypeError:
# logger.error('Unable to serialize a parsed message.')
# return
#===========================================================================
# Push a zlib compressed JSON representation of the message to
# announcers.
compressed_msg = zlib.compress(parsed_message)
logging.info("Message recieved, sending...")
sender.send(compressed_msg)
+50 -2
View File
@@ -4,8 +4,56 @@ Created on 15 Nov 2014
@author: james
'''
RELAY_RECEIVER_BINDINGS = ["tcp://*:8500"]
import logging.config
RELAY_SENDER_BINDINGS = ["tcp://*:9500"]
###############################################################################
# Relay settings
###############################################################################
RELAY_RECEIVER_BINDINGS = ["tcp://127.0.0.1:8500"]
RELAY_SENDER_BINDINGS = ["tcp://127.0.0.1:9500"]
RELAY_DECOMPRESS_MESSAGES = False
###############################################################################
# Gateway settings
###############################################################################
GATEWAY_SENDER_BINDINGS = ["tcp://127.0.0.1:8500"]
###############################################################################
# Logging Settings
###############################################################################
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
},
'simple': {
'format': '%(name)s -- %(levelname)s -- %(asctime)s: %(message)s'
},
},
'handlers': {
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'simple'
},
'null': {
'level': 'DEBUG',
'class': 'logging.NullHandler',
},
},
'loggers': {
'': {
'handlers': ['console'],
'level': 'INFO',
'propagate': True,
},
},
}
logging.config.dictConfig(LOGGING)