Package org.apache.pulsar.client.impl
Class ProducerImpl<T>
java.lang.Object
org.apache.pulsar.client.impl.ProducerBase<T>
org.apache.pulsar.client.impl.ProducerImpl<T>
- All Implemented Interfaces:
io.netty.util.TimerTask
,Closeable
,AutoCloseable
,Producer<T>
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static final class
protected static class
Queue implementation that is used as the pending messages queue.Nested classes/interfaces inherited from class org.apache.pulsar.client.impl.ProducerBase
ProducerBase.MultiSchemaMode
-
Field Summary
Modifier and TypeFieldDescriptionprotected final PulsarClientImpl
protected long
protected final long
protected URI
protected final String
Fields inherited from class org.apache.pulsar.client.impl.ProducerBase
conf, interceptors, multiSchemaMode, producerCreatedFuture, schema, schemaCache
-
Constructor Summary
ConstructorDescriptionProducerImpl
(PulsarClientImpl client, String topic, ProducerConfigurationData conf, CompletableFuture<Producer<T>> producerCreatedFuture, int partitionIndex, Schema<T> schema, ProducerInterceptors interceptors, Optional<String> overrideProducerName) -
Method Summary
Modifier and TypeMethodDescriptionint
protected boolean
protected boolean
protected boolean
void
connectionFailed
(PulsarClientException exception) protected ProducerImpl.OpSendMsgQueue
protected io.netty.buffer.ByteBuf
encryptMessage
(MessageMetadata msgMetadata, io.netty.buffer.ByteBuf compressedPayload) protected org.apache.pulsar.client.impl.HandlerState.State
getAndUpdateState
(UnaryOperator<org.apache.pulsar.client.impl.HandlerState.State> updater) protected Commands.ChecksumType
protected ClientCnx
Hook method for testing.long
long
long
int
int
protected org.apache.pulsar.client.impl.HandlerState.State
getState()
getStats()
boolean
boolean
protected void
protected void
recoverChecksumError
(ClientCnx cnx, long sequenceId) Checks message checksum to retry if message was corrupted while sending to broker.protected void
recoverNotAllowedError
(long sequenceId, String errorMsg) void
run
(io.netty.util.Timeout timeout) Process sendTimeout events.protected void
semaphoreRelease
(int releaseCountRequest) void
sendAsync
(Message<?> message, SendCallback callback) protected ByteBufPair
sendMessage
(long producerId, long sequenceId, int numMessages, MessageId messageId, MessageMetadata msgMetadata, io.netty.buffer.ByteBuf compressedPayload) protected ByteBufPair
sendMessage
(long producerId, long lowestSequenceId, long highestSequenceId, int numMessages, MessageMetadata msgMetadata, io.netty.buffer.ByteBuf compressedPayload) protected void
setRedirectedClusterURI
(String serviceUrl, String serviceUrlTls) protected void
setState
(org.apache.pulsar.client.impl.HandlerState.State s) void
terminated
(ClientCnx cnx) protected void
protected boolean
Computes checksum again and verifies it against existing checksum.Methods inherited from class org.apache.pulsar.client.impl.ProducerBase
beforeSend, close, flush, getConfiguration, getTopic, newMessage, newMessage, newMessage, onPartitionsChange, onSendAcknowledgement, producerCreatedFuture, send, send, sendAsync, sendAsync, toString
-
Field Details
-
producerId
protected final long producerId -
lastSequenceIdPushed
protected volatile long lastSequenceIdPushed -
client
-
topic
-
redirectedClusterURI
-
-
Constructor Details
-
ProducerImpl
public ProducerImpl(PulsarClientImpl client, String topic, ProducerConfigurationData conf, CompletableFuture<Producer<T>> producerCreatedFuture, int partitionIndex, Schema<T> schema, ProducerInterceptors interceptors, Optional<String> overrideProducerName)
-
-
Method Details
-
semaphoreRelease
protected void semaphoreRelease(int releaseCountRequest) -
createPendingMessagesQueue
-
getConnectionHandler
-
getLastSequenceId
public long getLastSequenceId()- Specified by:
getLastSequenceId
in interfaceProducer<T>
-
sendAsync
-
getNumOfPartitions
public int getNumOfPartitions()- Specified by:
getNumOfPartitions
in interfaceProducer<T>
-
encryptMessage
protected io.netty.buffer.ByteBuf encryptMessage(MessageMetadata msgMetadata, io.netty.buffer.ByteBuf compressedPayload) throws PulsarClientException - Throws:
PulsarClientException
-
sendMessage
protected ByteBufPair sendMessage(long producerId, long sequenceId, int numMessages, MessageId messageId, MessageMetadata msgMetadata, io.netty.buffer.ByteBuf compressedPayload) -
sendMessage
protected ByteBufPair sendMessage(long producerId, long lowestSequenceId, long highestSequenceId, int numMessages, MessageMetadata msgMetadata, io.netty.buffer.ByteBuf compressedPayload) -
getChecksumType
-
closeAsync
- Specified by:
closeAsync
in interfaceProducer<T>
- Specified by:
closeAsync
in classProducerBase<T>
-
isConnected
public boolean isConnected()- Specified by:
isConnected
in interfaceProducer<T>
-
getCnxIfReady
Hook method for testing. By returning null, it's possible to prevent messages being delivered to the broker.- Returns:
- cnx if OpSend messages should be written to open connection. Caller must verify that the returned cnx is not null before using reference.
-
getLastDisconnectedTimestamp
public long getLastDisconnectedTimestamp()- Specified by:
getLastDisconnectedTimestamp
in interfaceProducer<T>
-
isWritable
public boolean isWritable() -
terminated
-
recoverChecksumError
Checks message checksum to retry if message was corrupted while sending to broker. Recomputes checksum of the message header-payload again.- if matches with existing checksum: it means message was corrupt while sending to broker. So, resend message
- if doesn't match with existing checksum: it means message is already corrupt and can't retry again. So, fail send-message by failing callback
- Parameters:
cnx
-sequenceId
-
-
recoverNotAllowedError
-
verifyLocalBufferIsNotCorrupted
Computes checksum again and verifies it against existing checksum. If checksum doesn't match it means that message is corrupt.- Parameters:
op
-- Returns:
- returns true only if message is not modified and computed-checksum is same as previous checksum else return false that means that message is corrupted. Returns true if checksum is not present.
-
connectionOpened
-
connectionFailed
-
brokerChecksumSupportedVersion
public int brokerChecksumSupportedVersion() -
run
Process sendTimeout events.- Specified by:
run
in interfaceio.netty.util.TimerTask
- Throws:
Exception
-
flushAsync
- Specified by:
flushAsync
in interfaceProducer<T>
-
triggerFlush
protected void triggerFlush() -
processOpSendMsg
-
getDelayInMillis
public long getDelayInMillis() -
getConnectionId
-
getConnectedSince
-
getPendingQueueSize
public int getPendingQueueSize() -
getStats
-
getProducerName
- Specified by:
getProducerName
in interfaceProducer<T>
-
getClientCnx
-
setRedirectedClusterURI
protected void setRedirectedClusterURI(String serviceUrl, String serviceUrlTls) throws URISyntaxException - Throws:
URISyntaxException
-
changeToReadyState
protected boolean changeToReadyState() -
changeToRegisteringSchemaState
protected boolean changeToRegisteringSchemaState() -
getState
protected org.apache.pulsar.client.impl.HandlerState.State getState() -
changeToConnecting
protected boolean changeToConnecting() -
setState
protected void setState(org.apache.pulsar.client.impl.HandlerState.State s) -
getAndUpdateState
protected org.apache.pulsar.client.impl.HandlerState.State getAndUpdateState(UnaryOperator<org.apache.pulsar.client.impl.HandlerState.State> updater) -
getClient
-