Package io.micronaut.configuration.kafka
Class KafkaProducerFactory
java.lang.Object
io.micronaut.configuration.kafka.KafkaProducerFactory
- All Implemented Interfaces:
ProducerRegistry,TransactionalProducerRegistry
@Factory
public class KafkaProducerFactory
extends Object
implements ProducerRegistry, TransactionalProducerRegistry
A registry class for Kafka
Producer instances.- Since:
- 1.0
- Author:
- Graeme Rocher
-
Constructor Summary
ConstructorsConstructorDescriptionKafkaProducerFactory(io.micronaut.context.BeanContext beanContext, SerdeRegistry serdeRegistry, ProducerFactory producerFactory) Default constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidClosed the producer.<K,V> Producer<K, V> getProducer(@Nullable io.micronaut.inject.InjectionPoint<KafkaProducer<K, V>> injectionPoint, @Nullable AbstractKafkaProducerConfiguration<K, V> producerConfiguration) Creates a newKafkaProducerfor the given configuration.<K,V> Producer<K, V> getProducer(String id, io.micronaut.core.type.Argument<K> keyType, io.micronaut.core.type.Argument<V> valueType) Returns a managed Producer.<K,V> Producer<K, V> getTransactionalProducer(String id, String transactionalId, io.micronaut.core.type.Argument<K> keyType, io.micronaut.core.type.Argument<V> valueType) Returns a transactional managed Producer.protected voidstop()Shuts down any existing clients.
-
Constructor Details
-
KafkaProducerFactory
public KafkaProducerFactory(io.micronaut.context.BeanContext beanContext, SerdeRegistry serdeRegistry, ProducerFactory producerFactory) Default constructor.- Parameters:
beanContext- The bean contextserdeRegistry- The serde registryproducerFactory- The producer factory
-
-
Method Details
-
getProducer
@Bean @Any public <K,V> Producer<K,V> getProducer(@Nullable @Nullable io.micronaut.inject.InjectionPoint<KafkaProducer<K, V>> injectionPoint, @Nullable @Parameter @Nullable AbstractKafkaProducerConfiguration<K, V> producerConfiguration) Creates a newKafkaProducerfor the given configuration.- Type Parameters:
K- The key typeV- The value type- Parameters:
injectionPoint- The injection point used to create the beanproducerConfiguration- An optional producer configuration- Returns:
- The consumer
-
stop
@PreDestroy protected void stop()Shuts down any existing clients. -
getProducer
public <K,V> Producer<K,V> getProducer(String id, io.micronaut.core.type.Argument<K> keyType, io.micronaut.core.type.Argument<V> valueType) Description copied from interface:ProducerRegistryReturns a managed Producer.- Specified by:
getProducerin interfaceProducerRegistry- Type Parameters:
K- The key generic typeV- The value generic type- Parameters:
id- The id of the producer.keyType- The key typevalueType- The value type- Returns:
- The producer
-
getTransactionalProducer
public <K,V> Producer<K,V> getTransactionalProducer(String id, String transactionalId, io.micronaut.core.type.Argument<K> keyType, io.micronaut.core.type.Argument<V> valueType) Description copied from interface:TransactionalProducerRegistryReturns a transactional managed Producer.- Specified by:
getTransactionalProducerin interfaceTransactionalProducerRegistry- Type Parameters:
K- The key generic typeV- The value generic type- Parameters:
id- The client id of the producer.transactionalId- The transactional id of the producer.keyType- The key typevalueType- The value type- Returns:
- The producer
-
close
Description copied from interface:TransactionalProducerRegistryClosed the producer. Should be used for cases whenProducerFencedExceptionis thrown.- Specified by:
closein interfaceTransactionalProducerRegistry- Parameters:
producer- The producer
-