Package org.apache.pulsar.client.api.v5
Interface CheckpointConsumer<T>
- Type Parameters:
T- the type of message values
- All Superinterfaces:
AutoCloseable,Closeable
An unmanaged consumer designed for connector frameworks (Flink, Spark, etc.).
Unlike StreamConsumer and QueueConsumer, this consumer has no
broker-managed subscription — position tracking is entirely external. The connector
framework stores checkpoints in its own state backend and uses them to restore
on failure.
Internally, the consumer reads from all hash-range segments of a topic.
checkpoint() creates an atomic snapshot of positions across all segments,
returned as an opaque Checkpoint that can be serialized and stored externally.
This interface provides synchronous (blocking) operations. For non-blocking
usage, obtain an AsyncCheckpointConsumer via async().
-
Method Summary
Modifier and TypeMethodDescriptionasync()Return the asynchronous view of this consumer.Create a consistent checkpoint — an atomic snapshot of positions across all internal hash-range segments.voidclose()Close the consumer and release all resources.receive()Receive a single message, blocking indefinitely.Receive a single message, blocking up to the given timeout.receiveMulti(int maxMessages, Duration timeout) Receive a batch of messages, blocking up to the given timeout.topic()The topic this consumer reads from.
-
Method Details
-
topic
String topic()The topic this consumer reads from.- Returns:
- the fully qualified topic name
-
receive
Receive a single message, blocking indefinitely.- Returns:
- the received
Message - Throws:
PulsarClientException- if the consumer is closed or a connection error occurs
-
receive
Receive a single message, blocking up to the given timeout. Returnsnullif the timeout elapses without a message.- Parameters:
timeout- the maximum time to wait for a message- Returns:
- the received
Message, ornullif the timeout elapses - Throws:
PulsarClientException- if the consumer is closed or a connection error occurs
-
receiveMulti
Receive a batch of messages, blocking up to the given timeout.- Parameters:
maxMessages- the maximum number of messages to returntimeout- the maximum time to wait for messages- Returns:
- the received
Messagesbatch - Throws:
PulsarClientException- if the consumer is closed or a connection error occurs
-
checkpoint
Checkpoint checkpoint()Create a consistent checkpoint — an atomic snapshot of positions across all internal hash-range segments.The returned
Checkpointcan be serialized viaCheckpoint.toByteArray()and stored in the connector framework's state backend.- Returns:
- an opaque
Checkpointrepresenting the current read positions
-
async
AsyncCheckpointConsumer<T> async()Return the asynchronous view of this consumer.- Returns:
- the
AsyncCheckpointConsumercounterpart of this consumer
-
close
Close the consumer and release all resources.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
PulsarClientException- if an error occurs while closing the consumer
-