@InterfaceAudience.Public @InterfaceStability.Stable public interface Producer<T> extends Closeable
A single producer instance can be used across multiple threads.
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Close the producer and releases resources allocated.
|
CompletableFuture<Void> |
closeAsync()
Close the producer and releases resources allocated.
|
void |
flush()
Flush all the messages buffered in the client and wait until all messages have been successfully persisted.
|
CompletableFuture<Void> |
flushAsync()
Flush all the messages buffered in the client and wait until all messages have been successfully persisted.
|
long |
getLastDisconnectedTimestamp() |
long |
getLastSequenceId()
Get the last sequence id that was published by this producer.
|
String |
getProducerName() |
ProducerStats |
getStats()
Get statistics for the producer.
|
String |
getTopic() |
boolean |
isConnected() |
TypedMessageBuilder<T> |
newMessage()
Create a new message builder.
|
<V> TypedMessageBuilder<V> |
newMessage(Schema<V> schema)
Create a new message builder with schema, not required same parameterized type with the producer.
|
TypedMessageBuilder<T> |
newMessage(Transaction txn)
Create a new message builder with transaction.
|
MessageId |
send(T message)
Sends a message.
|
CompletableFuture<MessageId> |
sendAsync(T message)
Send a message asynchronously.
|
String getTopic()
String getProducerName()
MessageId send(T message) throws PulsarClientException
This call will be blocking until is successfully acknowledged by the Pulsar broker.
Use newMessage() to specify more properties than just the value on the message to be sent.
message - a messagePulsarClientException.TimeoutException - if the message was not correctly received by the system within the timeout periodPulsarClientException.AlreadyClosedException - if the producer was already closedPulsarClientExceptionCompletableFuture<MessageId> sendAsync(T message)
When the producer queue is full, by default this method will complete the future with an exception
PulsarClientException.ProducerQueueIsFullError
See ProducerBuilder.maxPendingMessages(int) to configure the producer queue size and
ProducerBuilder.blockIfQueueFull(boolean) to change the blocking behavior.
Use newMessage() to specify more properties than just the value on the message to be sent.
message - a byte array with the payload of the messagevoid flush()
throws PulsarClientException
PulsarClientExceptionflushAsync()CompletableFuture<Void> flushAsync()
flush()TypedMessageBuilder<T> newMessage()
This message builder allows to specify additional properties on the message. For example:
producer.newMessage()
.key(messageKey)
.value(myValue)
.property("user-defined-property", "value")
.send();
<V> TypedMessageBuilder<V> newMessage(Schema<V> schema)
newMessage()TypedMessageBuilder<T> newMessage(Transaction txn)
After the transaction commit, it will be made visible to consumer.
After the transaction abort, it will never be visible to consumer.
newMessage()long getLastSequenceId()
This represent either the automatically assigned
or custom sequence id (set on the TypedMessageBuilder)
that was published and acknowledged by the broker.
After recreating a producer with the same producer name, this will return the last message that was published in the previous producer session, or -1 if there no message was ever published.
ProducerStats getStats()
void close()
throws PulsarClientException
No more writes will be accepted from this producer. Waits until all pending write request are persisted. In case of errors, pending writes will not be retried.
close in interface AutoCloseableclose in interface CloseablePulsarClientException.AlreadyClosedException - if the producer was already closedPulsarClientExceptionCompletableFuture<Void> closeAsync()
No more writes will be accepted from this producer. Waits until all pending write request are persisted. In case of errors, pending writes will not be retried.
boolean isConnected()
long getLastDisconnectedTimestamp()
Copyright © 2017–2021 Apache Software Foundation. All rights reserved.