Package org.springframework.kafka.mock
Class MockProducerFactory<K,V>
java.lang.Object
org.springframework.kafka.mock.MockProducerFactory<K,V>
- Type Parameters:
K
- the key type.V
- the value type.
- All Implemented Interfaces:
ProducerFactory<K,
V>
Support the use of
MockProducer
in tests.- Since:
- 3.0.7
- Author:
- Gary Russell
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.springframework.kafka.core.ProducerFactory
ProducerFactory.Listener<K,
V> -
Field Summary
Fields inherited from interface org.springframework.kafka.core.ProducerFactory
DEFAULT_PHYSICAL_CLOSE_TIMEOUT
-
Constructor Summary
ConstructorDescriptionMockProducerFactory
(BiFunction<Boolean, String, org.apache.kafka.clients.producer.MockProducer<K, V>> producerProvider, String defaultTxId) Create an instance that supports transactions, with the supplied producer providerBiFunction
.MockProducerFactory
(Supplier<org.apache.kafka.clients.producer.MockProducer<K, V>> producerProvider) Create an instance that does not support transactional producers. -
Method Summary
Modifier and TypeMethodDescriptionCreate 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.boolean
Return true if the factory supports transactions.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.kafka.core.ProducerFactory
addListener, addListener, addPostProcessor, closeThreadBoundProducer, copyWithConfigurationOverride, getConfigurationProperties, getKeySerializer, getKeySerializerSupplier, getListeners, getPhysicalCloseTimeout, getPostProcessors, getTransactionIdPrefix, getValueSerializer, getValueSerializerSupplier, isProducerPerThread, removeConfig, removeListener, removePostProcessor, reset, updateConfigs
-
Constructor Details
-
MockProducerFactory
public MockProducerFactory(Supplier<org.apache.kafka.clients.producer.MockProducer<K, V>> producerProvider) Create an instance that does not support transactional producers.- Parameters:
producerProvider
- aSupplier
for aMockProducer
.
-
MockProducerFactory
public MockProducerFactory(BiFunction<Boolean, String, org.apache.kafka.clients.producer.MockProducer<K, V>> producerProvider, @Nullable String defaultTxId) Create an instance that supports transactions, with the supplied producer providerBiFunction
. The function has two parameters, a boolean indicating whether a transactional producer is being requested and, if true, the transaction id prefix for that producer.- Parameters:
producerProvider
- the provider function.defaultTxId
- the default transactional id.
-
-
Method Details
-
transactionCapable
public boolean transactionCapable()Description copied from interface:ProducerFactory
Return true if the factory supports transactions.- Specified by:
transactionCapable
in interfaceProducerFactory<K,
V> - Returns:
- true if transactional.
-
createProducer
Description copied from interface:ProducerFactory
Create a producer which will be transactional if the factory is so configured.- Specified by:
createProducer
in interfaceProducerFactory<K,
V> - Returns:
- the producer.
- See Also:
-
createProducer
Description copied from interface:ProducerFactory
Create a producer with an overridden transaction id prefix.- Specified by:
createProducer
in interfaceProducerFactory<K,
V> - Parameters:
txIdPrefix
- the transaction id prefix.- Returns:
- the producer.
-
createNonTransactionalProducer
Description copied from interface:ProducerFactory
Create a non-transactional producer.- Specified by:
createNonTransactionalProducer
in interfaceProducerFactory<K,
V> - Returns:
- the producer.
- See Also:
-