def connect_to_db(): global kafka print "Connecting to cassandra" try: connect_cassandra() except Exception as e: print e print "Connecting to kafka" kafka = connect_kafka() print "done with connecting"
def stream_ws(ws): global kafka # get the stream_id we're going to follow msg = ws.receive() topic = "live_updates.{}".format(msg) from uuid import uuid4 kafka = connect_kafka() consumer = SimpleConsumer(kafka, None, topic, auto_commit=False) while True: print "Fetching" try: msg = consumer.get_messages(timeout=.25)[0].message.value ws.send(msg) print "sent {}".format(msg) except Exception as e: print e print "nothing waiting"