Interface ProducerFactory<K,V>
- Type Parameters:
K- the key type.V- the value type.
- All Known Implementing Classes:
DefaultKafkaProducerFactory,MockProducerFactory
public interface ProducerFactory<K,V>
The strategy to produce a
Producer instance(s).- Author:
- Gary Russell, Thomas Strauß, Kwon YongHyun
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceCalled whenever a producer is added or removed. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptiondefault 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 voidIf the factory implementation uses thread-bound producers, call this method to close and release this thread's producer.default ProducerFactory<K, V> copyWithConfigurationOverride(Map<String, Object> overrideProperties) Copy the properties of the instance and the given properties to create a new producer factory.Create a non-transactional producer.Create a producer which will be transactional if the factory is so configured.createProducer(String txIdPrefix) Create a producer with an overridden transaction id prefix.Return an unmodifiable reference to the configuration map for this factory.default org.apache.kafka.common.serialization.Serializer<K> Return the configured key serializer (if provided as an object instead of a class name in the properties).Return a supplier for a key serializer.default List<ProducerFactory.Listener<K, V>> Get the current list of listeners.default DurationGet the physical close timeout.default List<ProducerPostProcessor<K, V>> Get the current list of post processors.default StringReturn the transaction id prefix.default org.apache.kafka.common.serialization.Serializer<V> Return the configured value serializer (if provided as an object instead of a class name in the properties).Return a supplier for a value serializer.default booleanReturn true when there is a producer per thread.default voidremoveConfig(String configKey) Remove the specified key from the configuration map.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 booleanReturn true if the factory supports transactions.default voidupdateConfigs(Map<String, Object> updates) Update the producer configuration map; useful for situations such as credential rotation.
-
Field Details
-
DEFAULT_PHYSICAL_CLOSE_TIMEOUT
The default close timeout duration as 30 seconds. -
FACTORY_DOES_NOT_SUPPORT_METHOD
Error message for unsupported factory methods.- See Also:
-
-
Method Details
-
createProducer
-
createProducer
-
createNonTransactionalProducer
-
transactionCapable
default boolean transactionCapable()Return true if the factory supports transactions.- Returns:
- true if transactional.
-
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
-
getValueSerializerSupplier
-
getKeySerializerSupplier
-
isProducerPerThread
default boolean isProducerPerThread()Return true when there is a producer per thread.- Returns:
- the producer per thread.
- Since:
- 2.5
-
getTransactionIdPrefix
-
getPhysicalCloseTimeout
Get the physical close timeout.- Returns:
- the timeout.
- Since:
- 2.5
-
addListener
Add a listener.- Parameters:
listener- the listener.- Since:
- 2.5.3
-
addListener
Add a listener at a specific index.- Parameters:
index- the index (list position).listener- the listener.- Since:
- 2.5.3
-
removeListener
Remove a listener.- Parameters:
listener- the listener.- Returns:
- true if removed.
- Since:
- 2.5.3
-
getListeners
Get the current list of listeners.- Returns:
- the listeners.
- Since:
- 2.5.3
-
addPostProcessor
Add a post processor.- Parameters:
postProcessor- the post processor.- Since:
- 2.5.3
-
removePostProcessor
Remove a post processor.- Parameters:
postProcessor- the post processor.- Returns:
- true if removed.
- Since:
- 2.5.3
-
getPostProcessors
Get the current list of post processors.- Returns:
- the post processors.
- Since:
- 2.5.3
-
updateConfigs
-
removeConfig
Remove the specified key from the configuration map.- Parameters:
configKey- the key to remove.- Since:
- 2.5.10
-
getKeySerializer
-
getValueSerializer
-
copyWithConfigurationOverride
Copy the properties of the instance and the given properties to create a new producer factory.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.
- Parameters:
overrideProperties- the properties to be applied to the new factory- Returns:
ProducerFactorywith properties applied- Since:
- 2.5.17
- See Also:
-