Package org.springframework.kafka.core
Interface ProducerFactory<K,V>
-
- Type Parameters:
K- the key type.V- the value type.
- All Known Implementing Classes:
DefaultKafkaProducerFactory
public interface ProducerFactory<K,V>The strategy to produce aProducerinstance(s).- Author:
- Gary Russell
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceProducerFactory.Listener<K,V>Called whenever a producer is added or removed.
-
Field Summary
Fields Modifier and Type Field Description static java.time.DurationDEFAULT_PHYSICAL_CLOSE_TIMEOUTThe default close timeout duration as 30 seconds.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default voidaddListener(int index, ProducerFactory.Listener<K,V> listener)Add a listener at a specific index.default voidaddListener(ProducerFactory.Listener<K,V> listener)Add a listener.default voidaddPostProcessor(ProducerPostProcessor<K,V> postProcessor)Add a post processor.default voidcloseProducerFor(java.lang.String transactionIdSuffix)Remove the specified producer from the cache and close it.default voidcloseThreadBoundProducer()If the factory implementation uses thread-bound producers, call this method to close and release this thread's producer.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.DurationgetPhysicalCloseTimeout()Get the physical close timeout.default java.util.List<ProducerPostProcessor<K,V>>getPostProcessors()Get the current list of post processors.default java.lang.StringgetTransactionIdPrefix()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 booleanisProducerPerConsumerPartition()Return the producerPerConsumerPartition.default booleanisProducerPerThread()Return true when there is a producer per thread.default booleanremoveListener(ProducerFactory.Listener<K,V> listener)Remove a listener.default booleanremovePostProcessor(ProducerPostProcessor<K,V> postProcessor)Remove a post processor.default voidreset()Reset any state in the factory, if supported.default booleantransactionCapable()Return true if the factory supports transactions.
-
-
-
Method Detail
-
createProducer
org.apache.kafka.clients.producer.Producer<K,V> createProducer()
Create a producer which will be transactional if the factory is so configured.- Returns:
- the producer.
- See Also:
transactionCapable()
-
createProducer
default org.apache.kafka.clients.producer.Producer<K,V> createProducer(java.lang.String txIdPrefix)
Create a producer with an overridden transaction id prefix.- Parameters:
txIdPrefix- the transaction id prefix.- Returns:
- the producer.
- Since:
- 2.3
-
createNonTransactionalProducer
default org.apache.kafka.clients.producer.Producer<K,V> createNonTransactionalProducer()
Create a non-transactional producer.- Returns:
- the producer.
- Since:
- 2.4.3
- See Also:
transactionCapable()
-
transactionCapable
default boolean transactionCapable()
Return true if the factory supports transactions.- Returns:
- true if transactional.
-
closeProducerFor
default void closeProducerFor(java.lang.String transactionIdSuffix)
Remove the specified producer from the cache and close it.- Parameters:
transactionIdSuffix- the producer's transaction id suffix.- Since:
- 1.3.8
-
isProducerPerConsumerPartition
default boolean isProducerPerConsumerPartition()
Return the producerPerConsumerPartition.- Returns:
- the producerPerConsumerPartition.
- Since:
- 1.3.8
-
closeThreadBoundProducer
default void closeThreadBoundProducer()
If the factory implementation uses thread-bound producers, call this method to close and release this thread's producer.- Since:
- 2.3
-
reset
default void reset()
Reset any state in the factory, if supported.- Since:
- 2.4
-
getConfigurationProperties
default java.util.Map<java.lang.String,java.lang.Object> getConfigurationProperties()
Return an unmodifiable reference to the configuration map for this factory. Useful for cloning to make a similar factory.- Returns:
- the configs.
- Since:
- 2.5
-
getValueSerializerSupplier
default java.util.function.Supplier<org.apache.kafka.common.serialization.Serializer<V>> getValueSerializerSupplier()
Return a supplier for a value serializer. Useful for cloning to make a similar factory.- Returns:
- the supplier.
- Since:
- 2.5
-
getKeySerializerSupplier
default java.util.function.Supplier<org.apache.kafka.common.serialization.Serializer<K>> getKeySerializerSupplier()
Return a supplier for a key serializer. Useful for cloning to make a similar factory.- Returns:
- the supplier.
- Since:
- 2.5
-
isProducerPerThread
default boolean isProducerPerThread()
Return true when there is a producer per thread.- Returns:
- the produver per thread.
- Since:
- 2.5
-
getTransactionIdPrefix
@Nullable default java.lang.String getTransactionIdPrefix()
Return the transaction id prefix.- Returns:
- the prefix or null if not configured.
- Since:
- 2.5
-
getPhysicalCloseTimeout
default java.time.Duration getPhysicalCloseTimeout()
Get the physical close timeout.- Returns:
- the timeout.
- Since:
- 2.5
-
addListener
default void addListener(ProducerFactory.Listener<K,V> listener)
Add a listener.- Parameters:
listener- the listener.- Since:
- 2.5.3
-
addListener
default void addListener(int index, ProducerFactory.Listener<K,V> listener)Add a listener at a specific index.- Parameters:
index- the index (list position).listener- the listener.- Since:
- 2.5.3
-
removeListener
default boolean removeListener(ProducerFactory.Listener<K,V> listener)
Remove a listener.- Parameters:
listener- the listener.- Returns:
- true if removed.
- Since:
- 2.5.3
-
getListeners
default java.util.List<ProducerFactory.Listener<K,V>> getListeners()
Get the current list of listeners.- Returns:
- the listeners.
- Since:
- 2.5.3
-
addPostProcessor
default void addPostProcessor(ProducerPostProcessor<K,V> postProcessor)
Add a post processor.- Parameters:
postProcessor- the post processor.- Since:
- 2.5.3
-
removePostProcessor
default boolean removePostProcessor(ProducerPostProcessor<K,V> postProcessor)
Remove a post processor.- Parameters:
postProcessor- the post processor.- Returns:
- true if removed.
- Since:
- 2.5.3
-
getPostProcessors
default java.util.List<ProducerPostProcessor<K,V>> getPostProcessors()
Get the current list of post processors.- Returns:
- the post processors.
- Since:
- 2.5.3
-
-