def get_events(topic, partition): # get and check parameters valid, result = __try_get_parameter_as_int('start_from', flask.request, True) if not valid: return result start_from = result stream_opts = {} valid, result = __try_get_parameter_as_int('batch_limit', flask.request, False, 1) if not valid: return result stream_opts['batch_limit'] = result valid, result = __try_get_parameter_as_int('batch_flush_timeout', flask.request, False, 0) if not valid: return result stream_opts['batch_flush_timeout'] = result valid, result = __try_get_parameter_as_int('batch_keep_alive_limit', flask.request, False, -1) if not valid: return result stream_opts['batch_keep_alive_limit'] = result valid, result = __try_get_parameter_as_int('stream_limit', flask.request, False, 0) if not valid: return result stream_opts['stream_limit'] = result valid, result = __try_get_parameter_as_int('stream_timeout', flask.request, False, 0) if not valid: return result stream_opts['stream_timeout'] = result # check that partition is integer if not partition.isdigit(): return {'detail': '"partition" path parameter should be an integer number'}, 400 else: partition = int(partition) # check that topic and partition exist if not __topic_exists(topic): return {'detail': 'topic not found'}, 404 if not __partition_exists(topic, partition): return {'detail': 'partition not found'}, 404 # returning generator in response will create a stream stream_generator = event_stream.create_stream_generator(kafka_pool, topic, partition, start_from, stream_opts) return flask.Response(stream_generator, mimetype = 'text/plain', status = 200)
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)