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 Details

    • KafkaProducerFactory

      public KafkaProducerFactory(io.micronaut.context.BeanContext beanContext, SerdeRegistry serdeRegistry, ProducerFactory producerFactory)
      Default constructor.
      Parameters:
      beanContext - The bean context
      serdeRegistry - The serde registry
      producerFactory - 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 new KafkaProducer for the given configuration.
      Type Parameters:
      K - The key type
      V - The value type
      Parameters:
      injectionPoint - The injection point used to create the bean
      producerConfiguration - 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 interface ProducerRegistry
      Type Parameters:
      K - The key generic type
      V - The value generic type
      Parameters:
      id - The id of the producer.
      keyType - The key type
      valueType - 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 interface TransactionalProducerRegistry
      Type Parameters:
      K - The key generic type
      V - The value generic type
      Parameters:
      id - The client id of the producer.
      transactionalId - The transactional id of the producer.
      keyType - The key type
      valueType - The value type
      Returns:
      The producer
    • close

      public void close(Producer<?,?> producer)
      Description copied from interface: TransactionalProducerRegistry
      Closed the producer. Should be used for cases when ProducerFencedException is thrown.
      Specified by:
      close in interface TransactionalProducerRegistry
      Parameters:
      producer - The producer