Example #1
0
def __get_events(topic, cursors):

    # get and check parameters
    stream_opts = {}
    try:
        stream_opts['batch_limit'] = get_int_parameter('batch_limit', flask.request, False, 1)
        stream_opts['batch_flush_timeout'] = get_int_parameter('batch_flush_timeout', flask.request, False, 0)
        stream_opts['batch_keep_alive_limit'] = get_int_parameter('batch_keep_alive_limit', flask.request, False, -1)
        stream_opts['stream_limit'] = get_int_parameter('stream_limit', flask.request, False, 0)
        stream_opts['stream_timeout'] = get_int_parameter('stream_timeout', flask.request, False, 0)
    except NotIntegerParameterException as e:
        return {'detail': '"%s" query parameter should be an integer number' % e.parameter}, 400
    except RequiredParameterNotFoundException as e:
        return {'detail': 'missing required query parameter "%s"' % e.parameter}, 400

    # check that partitions exist
    for cursor in cursors:
        if not __partition_exists(topic, int(cursor['partition'])):
            return {'detail': 'partition not found'}, 404

    # returning generator in response will create a stream
    stream_generator = event_stream.create_stream_generator(kafka_client_pool, topic, cursors, stream_opts, __get_uid())
    return flask.Response(stream_generator, mimetype = 'text/plain', status = 200)
Example #2
0
def get_events_from_single_partition(topic, partition):

    # check if topic exists
    if not __topic_exists(topic):
        return {'detail': 'topic not found'}, 404

    # create cursor for single partition
    try:
        start_from = get_int_parameter('start_from', flask.request, True, 0)
    except NotIntegerParameterException as e:
        return {'detail': '"%s" query parameter should be an integer number' % e.parameter}, 400
    except RequiredParameterNotFoundException as e:
        return {'detail': 'missing required query parameter "%s"' % e.parameter}, 400
    cursors = [{'partition': str(partition), 'offset': str(start_from)}]

    return __get_events(topic, cursors)