public interface PulsarClient
extends Closeable
Modifier and Type | Method and Description |
---|---|
static ClientBuilder |
builder()
Get a new builder instance that can used to configure and build a
PulsarClient instance. |
void |
close()
Close the PulsarClient and release all the resources.
|
CompletableFuture<Void> |
closeAsync()
Asynchronously close the PulsarClient and release all the resources.
|
static PulsarClient |
create(String serviceUrl)
Deprecated.
use
builder() to construct a client instance |
static PulsarClient |
create(String serviceUrl,
ClientConfiguration conf)
Deprecated.
use
builder() to construct a client instance |
Producer<byte[]> |
createProducer(String topic)
Deprecated.
use
newProducer() to build a new producer |
Producer<byte[]> |
createProducer(String topic,
ProducerConfiguration conf)
Deprecated.
use
newProducer() to build a new producer |
CompletableFuture<Producer<byte[]>> |
createProducerAsync(String topic)
Deprecated.
use
newProducer() to build a new producer |
CompletableFuture<Producer<byte[]>> |
createProducerAsync(String topic,
ProducerConfiguration conf)
Deprecated.
use
newProducer() to build a new producer |
Reader<byte[]> |
createReader(String topic,
MessageId startMessageId,
ReaderConfiguration conf)
Deprecated.
Use
newReader() to build a new reader |
CompletableFuture<Reader<byte[]>> |
createReaderAsync(String topic,
MessageId startMessageId,
ReaderConfiguration conf)
Deprecated.
Use
newReader() to build a new reader |
CompletableFuture<List<String>> |
getPartitionsForTopic(String topic)
Get the list of partitions for a given topic.
|
ConsumerBuilder<byte[]> |
newConsumer()
Create a consumer with default for subscribing on a specific topic
|
<T> ConsumerBuilder<T> |
newConsumer(Schema<T> schema)
Create a consumer with default for subscribing on a specific topic
Since 2.2, if you are creating a consumer with non-bytes schema on a non-existence topic, it will
automatically create the topic with the provided schema.
|
ProducerBuilder<byte[]> |
newProducer()
Create a producer with default for publishing on a specific topic
|
<T> ProducerBuilder<T> |
newProducer(Schema<T> schema)
Create a producer with default for publishing on a specific topic
|
ReaderBuilder<byte[]> |
newReader()
Create a topic reader for reading messages from the specified topic.
|
<T> ReaderBuilder<T> |
newReader(Schema<T> schema)
Create a topic reader for reading messages from the specified topic.
|
void |
shutdown()
Perform immediate shutdown of PulsarClient.
|
Consumer<byte[]> |
subscribe(String topic,
String subscription)
Deprecated.
Use
newConsumer() to build a new consumer |
Consumer<byte[]> |
subscribe(String topic,
String subscription,
ConsumerConfiguration conf)
Deprecated.
Use
newConsumer() to build a new consumer |
CompletableFuture<Consumer<byte[]>> |
subscribeAsync(String topic,
String subscription)
Deprecated.
Use
newConsumer() to build a new consumer |
CompletableFuture<Consumer<byte[]>> |
subscribeAsync(String topic,
String subscription,
ConsumerConfiguration conf)
Deprecated.
Use
newConsumer() to build a new consumer |
void |
updateServiceUrl(String serviceUrl)
Update the service URL this client is using.
|
static ClientBuilder builder()
PulsarClient
instance.ClientBuilder
@Deprecated static PulsarClient create(String serviceUrl) throws PulsarClientException
builder()
to construct a client instanceserviceUrl
- the url of the Pulsar endpoint to be usedPulsarClientException.InvalidServiceURL
- if the serviceUrl is invalidPulsarClientException
@Deprecated static PulsarClient create(String serviceUrl, ClientConfiguration conf) throws PulsarClientException
builder()
to construct a client instanceserviceUrl
- the url of the Pulsar endpoint to be usedconf
- the client configurationPulsarClientException.InvalidServiceURL
- if the serviceUrl is invalidPulsarClientException
ProducerBuilder<byte[]> newProducer()
Example:
Producer producer = client.newProducer().topic(myTopic).create();
ProducerBuilder
object to configure and construct the Producer
instance<T> ProducerBuilder<T> newProducer(Schema<T> schema)
Example:
Producer producer = client.newProducer(mySchema).topic(myTopic).create();
schema
- provide a way to convert between serialized data and domain objectsProducerBuilder
object to configure and construct the Producer
instanceConsumerBuilder<byte[]> newConsumer()
ConsumerBuilder
object to configure and construct the Consumer
instance<T> ConsumerBuilder<T> newConsumer(Schema<T> schema)
schema
- provide a way to convert between serialized data and domain objectsConsumerBuilder
object to configure and construct the Consumer
instanceReaderBuilder<byte[]> newReader()
The Reader provides a low-level abstraction that allows for manual positioning in the topic, without using a subscription. Reader can only work on non-partitioned topics.
ReaderBuilder
that can be used to configure and construct a Reader
instance<T> ReaderBuilder<T> newReader(Schema<T> schema)
The Reader provides a low-level abstraction that allows for manual positioning in the topic, without using a subscription. Reader can only work on non-partitioned topics.
schema
- provide a way to convert between serialized data and domain objectsReaderBuilder
that can be used to configure and construct a Reader
instance@Deprecated Producer<byte[]> createProducer(String topic) throws PulsarClientException
newProducer()
to build a new producerProducerConfiguration
for publishing on a specific topictopic
- The name of the topic where to producePulsarClientException.AlreadyClosedException
- if the client was already closedPulsarClientException.InvalidTopicNameException
- if the topic name is not validPulsarClientException.AuthenticationException
- if there was an error with the supplied credentialsPulsarClientException.AuthorizationException
- if the authorization to publish on topic was deniedPulsarClientException
@Deprecated CompletableFuture<Producer<byte[]>> createProducerAsync(String topic)
newProducer()
to build a new producerProducerConfiguration
for publishing on a specific topictopic
- The name of the topic where to produce@Deprecated Producer<byte[]> createProducer(String topic, ProducerConfiguration conf) throws PulsarClientException
newProducer()
to build a new producerProducerConfiguration
for publishing on a specific topictopic
- The name of the topic where to produceconf
- The ProducerConfiguration
objectPulsarClientException
- if it was not possible to create the producerInterruptedException
@Deprecated CompletableFuture<Producer<byte[]>> createProducerAsync(String topic, ProducerConfiguration conf)
newProducer()
to build a new producerProducerConfiguration
for publishing on a specific topictopic
- The name of the topic where to produceconf
- The ProducerConfiguration
object@Deprecated Consumer<byte[]> subscribe(String topic, String subscription) throws PulsarClientException
newConsumer()
to build a new consumerConsumerConfiguration
topic
- The name of the topicsubscription
- The name of the subscriptionConsumer
objectPulsarClientException
InterruptedException
@Deprecated CompletableFuture<Consumer<byte[]>> subscribeAsync(String topic, String subscription)
newConsumer()
to build a new consumerConsumerConfiguration
topic
- The topic namesubscription
- The subscription nameConsumer
object@Deprecated Consumer<byte[]> subscribe(String topic, String subscription, ConsumerConfiguration conf) throws PulsarClientException
newConsumer()
to build a new consumerConsumerConfiguration
topic
- The name of the topicsubscription
- The name of the subscriptionconf
- The ConsumerConfiguration
objectConsumer
objectPulsarClientException
@Deprecated CompletableFuture<Consumer<byte[]>> subscribeAsync(String topic, String subscription, ConsumerConfiguration conf)
newConsumer()
to build a new consumerConsumerConfiguration
topic
- The name of the topicsubscription
- The name of the subscriptionconf
- The ConsumerConfiguration
objectConsumer
object@Deprecated Reader<byte[]> createReader(String topic, MessageId startMessageId, ReaderConfiguration conf) throws PulsarClientException
newReader()
to build a new readerReaderConfiguration
for reading messages from the specified topic.
The Reader provides a low-level abstraction that allows for manual positioning in the topic, without using a subscription. Reader can only work on non-partitioned topics.
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.
topic
- The name of the topic where to readstartMessageId
- The message id where the reader will position itself. The first message returned will be the one after
the specified startMessageIdconf
- The ReaderConfiguration
objectReader
objectPulsarClientException
@Deprecated CompletableFuture<Reader<byte[]>> createReaderAsync(String topic, MessageId startMessageId, ReaderConfiguration conf)
newReader()
to build a new readerReaderConfiguration
for reading messages from the
specified topic.
The Reader provides a low-level abstraction that allows for manual positioning in the topic, without using a subscription. Reader can only work on non-partitioned topics.
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.
topic
- The name of the topic where to readstartMessageId
- The message id where the reader will position itself. The first message returned will be the one after
the specified startMessageIdconf
- The ReaderConfiguration
objectvoid updateServiceUrl(String serviceUrl) throws PulsarClientException
serviceUrl
- the new service URL this client should connect toPulsarClientException
- in case the serviceUrl is not validCompletableFuture<List<String>> getPartitionsForTopic(String topic)
Reader
, Consumer
or Producer
instances directly on a particular partition.topic
- the topic namevoid close() throws PulsarClientException
close
in interface AutoCloseable
close
in interface Closeable
PulsarClientException
- if the close operation failsCompletableFuture<Void> closeAsync()
PulsarClientException
- if the close operation failsvoid shutdown() throws PulsarClientException
PulsarClientException
- if the forceful shutdown fails