def create_reader(self, topic, start_message_id, reader_listener=None, receiver_queue_size=1000, reader_name=None): """ Create a reader on a particular topic **Args** * `topic`: The name of the topic. * `start_message_id`: The initial reader positioning is done by specifying a message id. The options are: * `MessageId.earliest`: Start reading from the earliest message available in the topic * `MessageId.latest`: Start reading from the end topic, only getting messages published after the reader was created * `MessageId`: When passing a particular message id, the reader will position itself on that specific position. The first message to be read will be the message next to the specified messageId. Message id can be serialized into a string and deserialized back into a `MessageId` object: # Serialize to string s = msg.message_id().serialize() # Deserialize from string msg_id = MessageId.deserialize(s) **Options** * `reader_listener`: Sets a message listener for the reader. When the listener is set, the application will receive messages through it. Calls to `reader.read_next()` will not be allowed. The listener function needs to accept (reader, message), for example: def my_listener(reader, message): # process message pass * `receiver_queue_size`: Sets the size of the reader receive queue. The reader receive queue controls how many messages can be accumulated by the reader before the application calls `read_next()`. Using a higher value could potentially increase the reader throughput at the expense of higher memory utilization. * `reader_name`: Sets the reader name. """ conf = _pulsar.ReaderConfiguration() if reader_listener: conf.reader_listener(reader_listener) conf.receiver_queue_size(receiver_queue_size) if reader_name: conf.reader_name(reader_name) c = Reader() c._reader = self._client.create_reader(topic, start_message_id, conf) c._client = self self._consumers.append(c) return c
def create_reader(self, topic, start_message_id, schema=schema.BytesSchema(), reader_listener=None, receiver_queue_size=1000, reader_name=None, subscription_role_prefix=None, is_read_compacted=False): """ Create a reader on a particular topic **Args** * `topic`: The name of the topic. * `start_message_id`: The initial reader positioning is done by specifying a message id. The options are: * `MessageId.earliest`: Start reading from the earliest message available in the topic * `MessageId.latest`: Start reading from the end topic, only getting messages published after the reader was created * `MessageId`: When passing a particular message id, the reader will position itself on that specific position. The first message to be read will be the message next to the specified messageId. Message id can be serialized into a string and deserialized back into a `MessageId` object: # Serialize to string s = msg.message_id().serialize() # Deserialize from string msg_id = MessageId.deserialize(s) **Options** * `schema`: Define the schema of the data that will be received by this reader. * `reader_listener`: Sets a message listener for the reader. When the listener is set, the application will receive messages through it. Calls to `reader.read_next()` will not be allowed. The listener function needs to accept (reader, message), for example: def my_listener(reader, message): # process message pass * `receiver_queue_size`: Sets the size of the reader receive queue. The reader receive queue controls how many messages can be accumulated by the reader before the application calls `read_next()`. Using a higher value could potentially increase the reader throughput at the expense of higher memory utilization. * `reader_name`: Sets the reader name. * `subscription_role_prefix`: Sets the subscription role prefix. * `is_read_compacted`: Selects whether to read the compacted version of the topic """ _check_type(str, topic, 'topic') _check_type(_pulsar.MessageId, start_message_id, 'start_message_id') _check_type(_schema.Schema, schema, 'schema') _check_type(int, receiver_queue_size, 'receiver_queue_size') _check_type_or_none(str, reader_name, 'reader_name') _check_type_or_none(str, subscription_role_prefix, 'subscription_role_prefix') _check_type(bool, is_read_compacted, 'is_read_compacted') conf = _pulsar.ReaderConfiguration() if reader_listener: conf.reader_listener(_listener_wrapper(reader_listener, schema)) conf.receiver_queue_size(receiver_queue_size) if reader_name: conf.reader_name(reader_name) if subscription_role_prefix: conf.subscription_role_prefix(subscription_role_prefix) conf.schema(schema.schema_info()) conf.read_compacted(is_read_compacted) c = Reader() c._reader = self._client.create_reader(topic, start_message_id, conf) c._client = self c._schema = schema self._consumers.append(c) return c