Class ProducerV1Impl
- All Implemented Interfaces:
Closeable,AutoCloseable,Producer
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close the producer and releases resources allocated.Close the producer and releases resources allocated.voidflush()Flush all the messages buffered in the client and wait until all messages have been successfully persisted.Flush all the messages buffered in the client asynchronously.longGet the last sequence id that was published by this producer.org.apache.pulsar.client.api.ProducerStatsgetStats()Get statistics for the producer.getTopic()booleanorg.apache.pulsar.client.api.MessageIdsend(byte[] value) Sends a message.org.apache.pulsar.client.api.MessageIdsend(org.apache.pulsar.client.api.Message<byte[]> value) Send a message.CompletableFuture<org.apache.pulsar.client.api.MessageId>sendAsync(byte[] arg0) Send a message asynchronouslyCompletableFuture<org.apache.pulsar.client.api.MessageId>sendAsync(org.apache.pulsar.client.api.Message<byte[]> arg0) Send a message asynchronously.
-
Constructor Details
-
ProducerV1Impl
public ProducerV1Impl(org.apache.pulsar.client.impl.ProducerImpl<byte[]> producer)
-
-
Method Details
-
close
public void close() throws org.apache.pulsar.client.api.PulsarClientExceptionDescription copied from interface:ProducerClose the producer and releases resources allocated. 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. -
closeAsync
Description copied from interface:ProducerClose the producer and releases resources allocated. 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.- Specified by:
closeAsyncin interfaceProducer- Returns:
- a future that can used to track when the producer has been closed
-
flush
public void flush() throws org.apache.pulsar.client.api.PulsarClientExceptionDescription copied from interface:ProducerFlush all the messages buffered in the client and wait until all messages have been successfully persisted. -
flushAsync
Description copied from interface:ProducerFlush all the messages buffered in the client asynchronously.- Specified by:
flushAsyncin interfaceProducer- Returns:
- a future that can be used to track when all the messages have been safely persisted.
- See Also:
-
getLastSequenceId
public long getLastSequenceId()Description copied from interface:ProducerGet the last sequence id that was published by this producer.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.
- Specified by:
getLastSequenceIdin interfaceProducer- Returns:
- the last sequence id published by this producer
-
getStats
public org.apache.pulsar.client.api.ProducerStats getStats()Description copied from interface:ProducerGet 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
-
isConnected
public boolean isConnected()- Specified by:
isConnectedin interfaceProducer- Returns:
- Whether the producer is connected to the broker
-
send
public org.apache.pulsar.client.api.MessageId send(byte[] value) throws org.apache.pulsar.client.api.PulsarClientException Description copied from interface:ProducerSends a message.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.- Specified by:
sendin interfaceProducer- Parameters:
value- a message- Returns:
- the message id assigned to the published message
- Throws:
org.apache.pulsar.client.api.PulsarClientException.TimeoutException- if the message was not correctly received by the system within the timeout periodorg.apache.pulsar.client.api.PulsarClientException.AlreadyClosedException- if the producer was already closedorg.apache.pulsar.client.api.PulsarClientException
-
send
public org.apache.pulsar.client.api.MessageId send(org.apache.pulsar.client.api.Message<byte[]> value) throws org.apache.pulsar.client.api.PulsarClientException Description copied from interface:ProducerSend a message.- Specified by:
sendin interfaceProducer- Parameters:
value- a message- Returns:
- the message id assigned to the published message
- Throws:
org.apache.pulsar.client.api.PulsarClientException.TimeoutException- if the message was not correctly received by the system within the timeout periodorg.apache.pulsar.client.api.PulsarClientException
-
sendAsync
Description copied from interface:ProducerSend a message asynchronouslyWhen the producer queue is full, by default this method will complete the future with an exception
PulsarClientException.ProducerQueueIsFullErrorSee
ProducerBuilder.maxPendingMessages(int)to configure the producer queue size andProducerBuilder.blockIfQueueFull(boolean)to change the blocking behavior.Use
#newMessage()to specify more properties than just the value on the message to be sent. -
sendAsync
public CompletableFuture<org.apache.pulsar.client.api.MessageId> sendAsync(org.apache.pulsar.client.api.Message<byte[]> arg0) Description copied from interface:ProducerSend a message asynchronously.When the returned
CompletableFutureis marked as completed successfully, the provided message will contain theMessageIdassigned by the broker to the published message.Example:
Message msg = MessageBuilder.create().setContent(myContent).build(); producer.sendAsync(msg).thenRun(v -> { System.out.println("Published message: " + msg.getMessageId()); }).exceptionally(e -> { // Failed to publish });When the producer queue is full, by default this method will complete the future with an exception
PulsarClientException.ProducerQueueIsFullErrorSee
ProducerBuilder.maxPendingMessages(int)to configure the producer queue size andProducerBuilder.blockIfQueueFull(boolean)to change the blocking behavior. -
getTopic
-
getProducerName
- Specified by:
getProducerNamein interfaceProducer- Returns:
- the producer name which could have been assigned by the system or specified by the client
-