public interface Producer<T> extends Closeable
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 |
getLastSequenceId()
Get the last sequence id that was published by this producer.
|
String |
getProducerName() |
ProducerStats |
getStats()
Get statistics for the producer
numMsgsSent : Number of messages sent in the current interval
numBytesSent : Number of bytes sent in the current interval
numSendFailed : Number of messages failed to send in the current interval
numAcksReceived : Number of acks received in the current interval
totalMsgsSent : Total number of messages sent
totalBytesSent : Total number of bytes sent
totalSendFailed : Total number of messages failed to send
totalAcksReceived: Total number of acks received
|
String |
getTopic() |
boolean |
isConnected() |
TypedMessageBuilder<T> |
newMessage()
Create a new message builder
This message builder allows to specify additional properties on the message.
|
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 closedPulsarClientException
CompletableFuture<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
PulsarClientException
flushAsync()
CompletableFuture<Void> flushAsync()
flush()
TypedMessageBuilder<T> newMessage()
producer.newMessage()
.key(messageKey)
.value(myValue)
.property("user-defined-property", "value")
.send();
long getLastSequenceId()
This represent either the automatically assigned or custom sequence id (set on the MessageBuilder
) 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
close
in interface AutoCloseable
close
in interface Closeable
PulsarClientException.AlreadyClosedException
- if the producer was already closedPulsarClientException
CompletableFuture<Void> closeAsync()
boolean isConnected()
Copyright © 2017–2019 Apache Software Foundation. All rights reserved.