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,org.apache.pulsar.client.api.Producer<T>
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static final classprotected static classQueue 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
FieldsModifier and TypeFieldDescriptionprotected final PulsarClientImplprotected longprotected final longprotected final StringFields inherited from class org.apache.pulsar.client.impl.ProducerBase
conf, interceptors, multiSchemaMode, producerCreatedFuture, schema, schemaCache -
Constructor Summary
ConstructorsConstructorDescriptionProducerImpl(PulsarClientImpl client, String topic, ProducerConfigurationData conf, CompletableFuture<org.apache.pulsar.client.api.Producer<T>> producerCreatedFuture, int partitionIndex, org.apache.pulsar.client.api.Schema<T> schema, ProducerInterceptors interceptors, Optional<String> overrideProducerName) -
Method Summary
Modifier and TypeMethodDescriptionintprotected booleanprotected booleanprotected booleanvoidconnectionFailed(org.apache.pulsar.client.api.PulsarClientException exception) voidprotected ProducerImpl.OpSendMsgQueueprotected io.netty.buffer.ByteBufencryptMessage(org.apache.pulsar.common.api.proto.MessageMetadata msgMetadata, io.netty.buffer.ByteBuf compressedPayload) protected org.apache.pulsar.client.impl.HandlerState.StategetAndUpdateState(UnaryOperator<org.apache.pulsar.client.impl.HandlerState.State> updater) protected org.apache.pulsar.common.protocol.Commands.ChecksumTypeprotected ClientCnxHook method for testing.longlonglongintintprotected org.apache.pulsar.client.impl.HandlerState.StategetState()getStats()booleanbooleanprotected voidprotected voidrecoverChecksumError(ClientCnx cnx, long sequenceId) Checks message checksum to retry if message was corrupted while sending to broker.protected voidrecoverNotAllowedError(long sequenceId, String errorMsg) voidrun(io.netty.util.Timeout timeout) Process sendTimeout events.protected voidsemaphoreRelease(int releaseCountRequest) voidsendAsync(org.apache.pulsar.client.api.Message<?> message, SendCallback callback) protected org.apache.pulsar.common.protocol.ByteBufPairsendMessage(long producerId, long sequenceId, int numMessages, org.apache.pulsar.common.api.proto.MessageMetadata msgMetadata, io.netty.buffer.ByteBuf compressedPayload) protected org.apache.pulsar.common.protocol.ByteBufPairsendMessage(long producerId, long lowestSequenceId, long highestSequenceId, int numMessages, org.apache.pulsar.common.api.proto.MessageMetadata msgMetadata, io.netty.buffer.ByteBuf compressedPayload) protected voidsetState(org.apache.pulsar.client.impl.HandlerState.State s) voidterminated(ClientCnx cnx) protected voidprotected booleanComputes 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
-
-
Constructor Details
-
ProducerImpl
public ProducerImpl(PulsarClientImpl client, String topic, ProducerConfigurationData conf, CompletableFuture<org.apache.pulsar.client.api.Producer<T>> producerCreatedFuture, int partitionIndex, org.apache.pulsar.client.api.Schema<T> schema, ProducerInterceptors interceptors, Optional<String> overrideProducerName)
-
-
Method Details
-
semaphoreRelease
protected void semaphoreRelease(int releaseCountRequest) -
createPendingMessagesQueue
-
getConnectionHandler
-
getLastSequenceId
public long getLastSequenceId()- Specified by:
getLastSequenceIdin interfaceorg.apache.pulsar.client.api.Producer<T>
-
sendAsync
-
getNumOfPartitions
public int getNumOfPartitions()- Specified by:
getNumOfPartitionsin interfaceorg.apache.pulsar.client.api.Producer<T>
-
encryptMessage
protected io.netty.buffer.ByteBuf encryptMessage(org.apache.pulsar.common.api.proto.MessageMetadata msgMetadata, io.netty.buffer.ByteBuf compressedPayload) throws org.apache.pulsar.client.api.PulsarClientException - Throws:
org.apache.pulsar.client.api.PulsarClientException
-
sendMessage
protected org.apache.pulsar.common.protocol.ByteBufPair sendMessage(long producerId, long sequenceId, int numMessages, org.apache.pulsar.common.api.proto.MessageMetadata msgMetadata, io.netty.buffer.ByteBuf compressedPayload) -
sendMessage
protected org.apache.pulsar.common.protocol.ByteBufPair sendMessage(long producerId, long lowestSequenceId, long highestSequenceId, int numMessages, org.apache.pulsar.common.api.proto.MessageMetadata msgMetadata, io.netty.buffer.ByteBuf compressedPayload) -
getChecksumType
protected org.apache.pulsar.common.protocol.Commands.ChecksumType getChecksumType() -
closeAsync
- Specified by:
closeAsyncin interfaceorg.apache.pulsar.client.api.Producer<T>- Specified by:
closeAsyncin classProducerBase<T>
-
isConnected
public boolean isConnected()- Specified by:
isConnectedin interfaceorg.apache.pulsar.client.api.Producer<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:
getLastDisconnectedTimestampin interfaceorg.apache.pulsar.client.api.Producer<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
public void connectionFailed(org.apache.pulsar.client.api.PulsarClientException exception) -
brokerChecksumSupportedVersion
public int brokerChecksumSupportedVersion() -
run
Process sendTimeout events.- Specified by:
runin interfaceio.netty.util.TimerTask- Throws:
Exception
-
flushAsync
- Specified by:
flushAsyncin interfaceorg.apache.pulsar.client.api.Producer<T>
-
triggerFlush
protected void triggerFlush() -
processOpSendMsg
-
getDelayInMillis
public long getDelayInMillis() -
getConnectionId
-
getConnectedSince
-
getPendingQueueSize
public int getPendingQueueSize() -
getStats
- Specified by:
getStatsin interfaceorg.apache.pulsar.client.api.Producer<T>
-
getProducerName
- Specified by:
getProducerNamein interfaceorg.apache.pulsar.client.api.Producer<T>
-
getClientCnx
-
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
-