K - the key type.V - the value type.public interface ProducerFactory<K,V>
Producer instance(s).| Modifier and Type | Interface and Description |
|---|---|
static interface |
ProducerFactory.Listener<K,V>
Called whenever a producer is added or removed.
|
| Modifier and Type | Field and Description |
|---|---|
static java.time.Duration |
DEFAULT_PHYSICAL_CLOSE_TIMEOUT
The default close timeout duration as 30 seconds.
|
| Modifier and Type | Method and Description |
|---|---|
default void |
addListener(int index,
ProducerFactory.Listener<K,V> listener)
Add a listener at a specific index.
|
default void |
addListener(ProducerFactory.Listener<K,V> listener)
Add a listener.
|
default void |
addPostProcessor(ProducerPostProcessor<K,V> postProcessor)
Add a post processor.
|
default void |
closeProducerFor(java.lang.String transactionIdSuffix)
Remove the specified producer from the cache and close it.
|
default void |
closeThreadBoundProducer()
If the factory implementation uses thread-bound producers, call this method to
close and release this thread's producer.
|
default ProducerFactory<K,V> |
copyWithConfigurationOverride(java.util.Map<java.lang.String,java.lang.Object> overrideProperties)
Copy the properties of the instance and the given properties to create a new producer factory.
|
default org.apache.kafka.clients.producer.Producer<K,V> |
createNonTransactionalProducer()
Create a non-transactional producer.
|
org.apache.kafka.clients.producer.Producer<K,V> |
createProducer()
Create a producer which will be transactional if the factory is so configured.
|
default org.apache.kafka.clients.producer.Producer<K,V> |
createProducer(java.lang.String txIdPrefix)
Create a producer with an overridden transaction id prefix.
|
default java.util.Map<java.lang.String,java.lang.Object> |
getConfigurationProperties()
Return an unmodifiable reference to the configuration map for this factory.
|
default java.util.function.Supplier<org.apache.kafka.common.serialization.Serializer<K>> |
getKeySerializerSupplier()
Return a supplier for a key serializer.
|
default java.util.List<ProducerFactory.Listener<K,V>> |
getListeners()
Get the current list of listeners.
|
default java.time.Duration |
getPhysicalCloseTimeout()
Get the physical close timeout.
|
default java.util.List<ProducerPostProcessor<K,V>> |
getPostProcessors()
Get the current list of post processors.
|
default java.lang.String |
getTransactionIdPrefix()
Return the transaction id prefix.
|
default java.util.function.Supplier<org.apache.kafka.common.serialization.Serializer<V>> |
getValueSerializerSupplier()
Return a supplier for a value serializer.
|
default boolean |
isProducerPerConsumerPartition()
Return the producerPerConsumerPartition.
|
default boolean |
isProducerPerThread()
Return true when there is a producer per thread.
|
default void |
removeConfig(java.lang.String configKey)
Remove the specified key from the configuration map.
|
default boolean |
removeListener(ProducerFactory.Listener<K,V> listener)
Remove a listener.
|
default boolean |
removePostProcessor(ProducerPostProcessor<K,V> postProcessor)
Remove a post processor.
|
default void |
reset()
Reset any state in the factory, if supported.
|
default boolean |
transactionCapable()
Return true if the factory supports transactions.
|
default void |
updateConfigs(java.util.Map<java.lang.String,java.lang.Object> updates)
Update the producer configuration map; useful for situations such as
credential rotation.
|
static final java.time.Duration DEFAULT_PHYSICAL_CLOSE_TIMEOUT
org.apache.kafka.clients.producer.Producer<K,V> createProducer()
transactionCapable()default org.apache.kafka.clients.producer.Producer<K,V> createProducer(java.lang.String txIdPrefix)
txIdPrefix - the transaction id prefix.default org.apache.kafka.clients.producer.Producer<K,V> createNonTransactionalProducer()
transactionCapable()default boolean transactionCapable()
default void closeProducerFor(java.lang.String transactionIdSuffix)
transactionIdSuffix - the producer's transaction id suffix.default boolean isProducerPerConsumerPartition()
default void closeThreadBoundProducer()
default void reset()
default java.util.Map<java.lang.String,java.lang.Object> getConfigurationProperties()
default java.util.function.Supplier<org.apache.kafka.common.serialization.Serializer<V>> getValueSerializerSupplier()
default java.util.function.Supplier<org.apache.kafka.common.serialization.Serializer<K>> getKeySerializerSupplier()
default boolean isProducerPerThread()
@Nullable default java.lang.String getTransactionIdPrefix()
default java.time.Duration getPhysicalCloseTimeout()
default void addListener(ProducerFactory.Listener<K,V> listener)
listener - the listener.default void addListener(int index,
ProducerFactory.Listener<K,V> listener)
index - the index (list position).listener - the listener.default boolean removeListener(ProducerFactory.Listener<K,V> listener)
listener - the listener.default java.util.List<ProducerFactory.Listener<K,V>> getListeners()
default void addPostProcessor(ProducerPostProcessor<K,V> postProcessor)
postProcessor - the post processor.default boolean removePostProcessor(ProducerPostProcessor<K,V> postProcessor)
postProcessor - the post processor.default java.util.List<ProducerPostProcessor<K,V>> getPostProcessors()
default void updateConfigs(java.util.Map<java.lang.String,java.lang.Object> updates)
updates - the configuration properties to update.default void removeConfig(java.lang.String configKey)
configKey - the key to remove.default ProducerFactory<K,V> copyWithConfigurationOverride(java.util.Map<java.lang.String,java.lang.Object> overrideProperties)
The copy shall prioritize the override properties over the configured values. It is in the responsibility of the factory implementation to make sure the configuration of the new factory is identical, complete and correct.
ProducerPostProcessor and Listeners must stay intact.
If the factory does not implement this method, an exception will be thrown.
overrideProperties - the properties to be applied to the new factoryProducerFactory with properties
appliedKafkaTemplate(ProducerFactory, java.util.Map)