Esempio n. 1
0
def run_server():
    '''
    Runs the Tornado Server and begins Kafka consumption
    '''

    if not utils.topic_exists(constants.TOPIC_TURNSTILE_SUMMARY):
        logger.fatal(
            'Ensure that the KSQL Command has run successfully before running the web server!'
        )
        exit(1)
    if not utils.topic_exists(constants.TOPIC_STATIONS_TABLE_V1):
        logger.fatal(
            'Ensure that Faust Streaming is running successfully before running the web server!'
        )
        exit(1)

    weather_model = Weather()
    lines = Lines()

    application = tornado.web.Application([(r'/', MainHandler, {
        'weather': weather_model,
        'lines': lines
    })])
    application.listen(constants.SERVER_PORT)

    # Build kafka consumers
    consumers = [
        KafkaConsumer(
            constants.TOPIC_WEATHER_V1,
            weather_model.process_message,
            offset_earliest=True,
        ),
        KafkaConsumer(
            constants.TOPIC_STATIONS_TABLE_V1,
            lines.process_message,
            offset_earliest=True,
            is_avro=False,
        ),
        KafkaConsumer(
            constants.TOPIC_ARRIVALS_REGEX,
            lines.process_message,
            offset_earliest=True,
        ),
        KafkaConsumer(
            constants.TOPIC_TURNSTILE_SUMMARY,
            lines.process_message,
            offset_earliest=True,
            is_avro=False,
        )
    ]

    try:
        logger.info(
            f'Transit Status Page running at http://localhost:{constants.SERVER_PORT}'
        )
        for consumer in consumers:
            tornado.ioloop.IOLoop.current().spawn_callback(consumer.consume)
        tornado.ioloop.IOLoop.current().start()
    except KeyboardInterrupt:
        logger.info('shutting down server')
        tornado.ioloop.IOLoop.current().stop()
        for consumer in consumers:
            consumer.close()
Esempio n. 2
0
def run_server():
    """Runs the Tornado Server and begins Kafka consumption"""
    if topic_check.topic_exists(
            "cta.trains.monitor.turnstile.summarized") is False:
        logger.fatal(
            "Ensure that the KSQL Command has run successfully before running the web server!"
        )
        exit(1)
    if topic_check.topic_exists(
            "cta.trains.monitor.stations.transformed") is False:
        logger.fatal(
            "Ensure that Faust Streaming is running successfully before running the web server!"
        )
        exit(1)

    weather_model = Weather()
    lines = Lines()

    application = tornado.web.Application([(r"/", MainHandler, {
        "weather": weather_model,
        "lines": lines
    })])
    application.listen(8888)

    # Build kafka consumers
    consumers = [
        KafkaConsumer(
            "cta.trains.monitor.weather",
            weather_model.process_message,
            offset_earliest=True,
        ),
        KafkaConsumer(
            "cta.trains.monitor.stations.transformed",
            lines.process_message,
            offset_earliest=True,
            is_avro=False,
        ),
        KafkaConsumer(
            "^cta.trains.monitor.stations.arrivals.*",
            lines.process_message,
            offset_earliest=True,
        ),
        KafkaConsumer(
            "cta.trains.monitor.turnstile.summarized",
            lines.process_message,
            offset_earliest=True,
            is_avro=False,
        ),
    ]

    try:
        logger.info(
            "Open a web browser to http://localhost:8888 to see the Transit Status Page"
        )
        for consumer in consumers:
            tornado.ioloop.IOLoop.current().spawn_callback(consumer.consume)

        tornado.ioloop.IOLoop.current().start()
    except KeyboardInterrupt as e:
        logger.info("shutting down server")
        tornado.ioloop.IOLoop.current().stop()
        for consumer in consumers:
            consumer.close()
def run_server():
    """Runs the Tornado Server and begins Kafka consumption"""
    if topic_check.topic_exists("TURNSTILE_SUMMARY") is False:
        logger.fatal(
            "Ensure that the KSQL Command has run successfully before running the web server!"
        )
        exit(1)

    if topic_check.topic_pattern_match("stations.table") is False:
        logger.fatal(
            "Ensure that Faust Streaming is running successfully before running the web server!"
        )
        exit(1)

    weather_model = Weather()
    lines = Lines()

    application = tornado.web.Application([(r"/", MainHandler, {
        "weather": weather_model,
        "lines": lines
    })])
    application.listen(WEB_SERVER_PORT)

    # Build kafka consumers
    consumers = [
        KafkaConsumer(
            "org.chicago.cta.weather.v1",
            weather_model.process_message,
            offset_earliest=True,
        ),
        KafkaConsumer(
            "org.chicago.cta.stations.table.v1",
            lines.process_message,
            offset_earliest=True,
            is_avro=False,
        ),
        KafkaConsumer(
            "org.chicago.cta.station.arrivals.v1",
            lines.process_message,
            offset_earliest=True,
        ),
        KafkaConsumer(
            "TURNSTILE_SUMMARY",
            lines.process_message,
            offset_earliest=True,
            is_avro=False,
        ),
    ]

    try:
        logger.info(
            f"Open a web browser to http://localhost:{WEB_SERVER_PORT} to see the Transit Status Page"
        )
        for consumer in consumers:
            tornado.ioloop.IOLoop.current().spawn_callback(consumer.consume)

        tornado.ioloop.IOLoop.current().start()
    except KeyboardInterrupt as e:
        logger.info("shutting down server")
        tornado.ioloop.IOLoop.current().stop()
        for consumer in consumers:
            consumer.close()
Esempio n. 4
0
def run_server():
    """Runs the Tornado Server and begins Kafka consumption"""
    if topic_check.topic_exists(CtaTopics.TURNSTILES_SUMMARY) is False:
        logger.fatal(
            "Ensure that the KSQL Command has run successfully before running the web server!"
        )
        exit(1)
    if topic_check.topic_exists(CtaTopics.STATIONS_LINE) is False:
        logger.fatal(
            "Ensure that Faust Streaming is running successfully before running the web server!"
        )
        exit(1)

    weather_model = Weather()
    lines = Lines()

    application = tornado.web.Application([(r"/", MainHandler, {
        "weather": weather_model,
        "lines": lines
    })])
    application.listen(8888)

    # Build kafka consumers
    consumers = [
        KafkaConsumer(
            CtaTopics.WEATHER,
            weather_model.process_message,
            offset_earliest=True,
        ),
        KafkaConsumer(
            CtaTopics.STATIONS_LINE,
            lines.process_message,
            offset_earliest=True,
            is_avro=False,
        ),
        KafkaConsumer(
            f"^{CtaTopics.ARRIVALS_PREFIX}.*",
            lines.process_message,
            offset_earliest=True,
        ),
        KafkaConsumer(
            CtaTopics.TURNSTILES_SUMMARY,
            lines.process_message,
            offset_earliest=True,
            is_avro=False,
        ),
    ]

    try:
        logger.info(
            "Open a web browser to http://localhost:8888 to see the Transit Status Page"
        )
        for consumer in consumers:
            tornado.ioloop.IOLoop.current().spawn_callback(consumer.consume)

        tornado.ioloop.IOLoop.current().start()
    except KeyboardInterrupt:
        logger.info("shutting down server")
        tornado.ioloop.IOLoop.current().stop()
        for consumer in consumers:
            consumer.close()