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
ConstructorDescriptionKafkaProducerFactory
(io.micronaut.context.BeanContext beanContext, SerdeRegistry serdeRegistry, ProducerFactory producerFactory) Default constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Closed the producer.<K,
V> Producer<K, V> getProducer
(@Nullable io.micronaut.inject.InjectionPoint<KafkaProducer<K, V>> injectionPoint, @Nullable AbstractKafkaProducerConfiguration<K, V> producerConfiguration) Creates a newKafkaProducer
for 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 void
stop()
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 newKafkaProducer
for 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:ProducerRegistry
Returns a managed Producer.- Specified by:
getProducer
in 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:TransactionalProducerRegistry
Returns a transactional managed Producer.- Specified by:
getTransactionalProducer
in 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:TransactionalProducerRegistry
Closed the producer. Should be used for cases whenProducerFencedException
is thrown.- Specified by:
close
in interfaceTransactionalProducerRegistry
- Parameters:
producer
- The producer
-