public class KafkaClientFactory extends Object
| Constructor and Description |
|---|
KafkaClientFactory() |
| Modifier and Type | Method and Description |
|---|---|
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. |
static KafkaClientFactory |
getInstance() |
public static KafkaClientFactory getInstance()
public org.apache.kafka.clients.producer.Producer<byte[],io.opentelemetry.proto.metrics.v1.MetricsData> get(ProducerClientConfig producerConfig, Properties properties)
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.
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.Producer instance, potentially wrapped in a ReferenceTrackingProxy.