Class KafkaClientFactory
java.lang.Object
io.confluent.telemetry.exporter.kafka.KafkaClientFactory
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.apache.kafka.clients.producer.Producer<byte[], io.opentelemetry.proto.metrics.v1.MetricsData> get(ProducerClientConfig producerConfig, Properties properties) Retrieves or creates aKafkaProducerinstance based on the provided configuration.static KafkaClientFactory
-
Constructor Details
-
KafkaClientFactory
public KafkaClientFactory()
-
-
Method Details
-
getInstance
-
get
public org.apache.kafka.clients.producer.Producer<byte[], io.opentelemetry.proto.metrics.v1.MetricsData> get(ProducerClientConfig producerConfig, Properties properties) Retrieves or creates aKafkaProducerinstance based on the provided configuration.If a
ProducerClientConfigis provided, this method attempts to reuse an existingCloseableReferenceTrackerfor 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
Produceris a proxy that tracks references, ensuring that the underlying staticKafkaProduceris closed only when all references (leases) are released.If
producerConfigis null, a new, non-staticKafkaProduceris created directly using the providedproperties.- 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-staticKafkaProducer.- Returns:
- A
Producerinstance, potentially wrapped in aReferenceTrackingProxy.
-