Class KafkaClientFactory

java.lang.Object
io.confluent.telemetry.exporter.kafka.KafkaClientFactory

public class KafkaClientFactory extends Object
  • Constructor Details

    • KafkaClientFactory

      public KafkaClientFactory()
  • Method Details

    • getInstance

      public static KafkaClientFactory getInstance()
    • get

      public org.apache.kafka.clients.producer.Producer<byte[], io.opentelemetry.proto.metrics.v1.MetricsData> get(ProducerClientConfig producerConfig, Properties properties)
      Retrieves or creates a KafkaProducer instance based on the provided configuration.

      If a ProducerClientConfig is provided, this method attempts to reuse an existing CloseableReferenceTracker for the given client name. If no tracker exists, or if the existing tracker's configuration has changed and the tracker is marked for replacement, a new tracker is created and stored, replacing the old one to allow GC to collect it.

      The returned Producer is a proxy that tracks references, ensuring that the underlying static KafkaProducer is closed only when all references (leases) are released.

      If producerConfig is null, a new, non-static KafkaProducer is created directly using the provided properties.

      Parameters:
      producerConfig - The configuration for the producer. Can be null, in which case a non-static producer is created.
      properties - The properties to use for creating a non-static KafkaProducer.
      Returns:
      A Producer instance, potentially wrapped in a ReferenceTrackingProxy.