Package org.apache.pulsar.client.api.v5
Interface PulsarClient
- All Superinterfaces:
AutoCloseable
Entry point for the Pulsar client. Provides factory methods for creating producers,
consumers, and transactions.
Instances are created via builder().
A PulsarClient manages internal resources such as connections, threads,
and memory buffers. It must be closed when no longer needed.
-
Method Summary
Modifier and TypeMethodDescriptionstatic PulsarClientBuilderbuilder()Create a new client builder.voidclose()Close the client and release all resources, waiting for pending operations to complete.Asynchronous counterpart ofclose().<T> CheckpointConsumerBuilder<T> newCheckpointConsumer(Schema<T> schema) Create a checkpoint consumer builder with a specific schema.<T> ProducerBuilder<T> newProducer(Schema<T> schema) Create a producer builder with a specific schema.<T> QueueConsumerBuilder<T> newQueueConsumer(Schema<T> schema) Create a queue consumer builder with a specific schema.<T> StreamConsumerBuilder<T> newStreamConsumer(Schema<T> schema) Create a stream consumer builder with a specific schema.Create a new transaction, blocking until it is ready.Asynchronous counterpart ofnewTransaction().voidshutdown()Shutdown the client instance.
-
Method Details
-
builder
Create a new client builder.- Returns:
- a new
PulsarClientBuilderfor configuring the client
-
newProducer
Create a producer builder with a specific schema.- Type Parameters:
T- the message value type- Parameters:
schema- the schema used for serialization/deserialization- Returns:
- a new
ProducerBuilderfor configuring the producer
-
newStreamConsumer
Create a stream consumer builder with a specific schema.- Type Parameters:
T- the message value type- Parameters:
schema- the schema used for serialization/deserialization- Returns:
- a new
StreamConsumerBuilderfor configuring the stream consumer
-
newQueueConsumer
Create a queue consumer builder with a specific schema.- Type Parameters:
T- the message value type- Parameters:
schema- the schema used for serialization/deserialization- Returns:
- a new
QueueConsumerBuilderfor configuring the queue consumer
-
newCheckpointConsumer
Create a checkpoint consumer builder with a specific schema.Checkpoint consumers are unmanaged — position tracking is external. Designed for connector frameworks (Flink, Spark) that manage their own state.
- Type Parameters:
T- the message value type- Parameters:
schema- the schema used for serialization/deserialization- Returns:
- a new
CheckpointConsumerBuilderfor configuring the checkpoint consumer
-
newTransaction
Create a new transaction, blocking until it is ready. The transaction timeout is taken from the client-wideTransactionPolicyconfigured onPulsarClientBuilder.transactionPolicy(org.apache.pulsar.client.api.v5.config.TransactionPolicy).- Returns:
- a new
Transactionin theTransaction.State.OPENstate - Throws:
PulsarClientException- if the transaction cannot be created (e.g., transaction coordinator unavailable or the client is closed)
-
newTransactionAsync
CompletableFuture<Transaction> newTransactionAsync()Asynchronous counterpart ofnewTransaction().- Returns:
- a
CompletableFuturethat completes with a newTransactionin theTransaction.State.OPENstate, or completes exceptionally withPulsarClientExceptionon failure
-
close
Close the client and release all resources, waiting for pending operations to complete.- Specified by:
closein interfaceAutoCloseable- Throws:
PulsarClientException- if an error occurs while closing the client
-
closeAsync
CompletableFuture<Void> closeAsync()Asynchronous counterpart ofclose().- Returns:
- a
CompletableFuturethat completes when the client has finished closing, or completes exceptionally withPulsarClientExceptionon failure
-
shutdown
void shutdown()Shutdown the client instance.Release all resources used by the client, without waiting for pending operations to complete.
-