Class ApacheKafkaProducerAdapter
java.lang.Object
com.linkedin.venice.pubsub.adapter.kafka.producer.ApacheKafkaProducerAdapter
- All Implemented Interfaces:
PubSubProducerAdapter
A wrapper over Apache Kafka producer which implements
PubSubProducerAdapter-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose(long closeTimeOutMs) voidflush()it.unimi.dsi.fastutil.objects.Object2DoubleMap<String>intgetNumberOfPartitions(String topic) Deprecated.sendMessage(PubSubTopicPartition pubSubTopicPartition, byte[] keyBytes, byte[] valueBytes, PubSubMessageHeaders pubsubMessageHeaders, PubSubProducerCallback pubsubProducerCallback) Sends a message to a PubSub topic asynchronously and returns aCompletableFuturerepresenting the result of the produce operation.sendMessage(String topic, Integer partition, KafkaKey key, KafkaMessageEnvelope value, PubSubMessageHeaders pubsubMessageHeaders, PubSubProducerCallback pubsubProducerCallback) Sends a message to the Kafka Producer.
-
Constructor Details
-
ApacheKafkaProducerAdapter
- Parameters:
producerConfig- contains producer configs
-
-
Method Details
-
getNumberOfPartitions
Deprecated.N.B.: This is an expensive call, the result of which should be cached.- Specified by:
getNumberOfPartitionsin interfacePubSubProducerAdapter- Parameters:
topic- for which we want to request the number of partitions.- Returns:
- the number of partitions for this topic.
-
sendMessage
public CompletableFuture<PubSubProduceResult> sendMessage(String topic, Integer partition, KafkaKey key, KafkaMessageEnvelope value, PubSubMessageHeaders pubsubMessageHeaders, PubSubProducerCallback pubsubProducerCallback) Sends a message to the Kafka Producer. If everything is set up correctly, it will show up in Kafka log.- Specified by:
sendMessagein interfacePubSubProducerAdapter- Parameters:
topic- - The topic to be sent to.key- - The key of the message to be sent.value- - TheKafkaMessageEnvelope, which acts as the Kafka value.pubsubProducerCallback- - The callback function, which will be triggered when Kafka client sends out the message.partition- The partition to which the message should be sent.pubsubMessageHeaders- Additional headers to be included with the message.- Returns:
- - A
FutureofPubSubProduceResult, which will be completed when the message is sent to pub-sub server successfully. - Throws:
PubSubOpTimeoutException- - If the operation times out.PubSubTopicAuthorizationException- - If the producer is not authorized to send to the topic.PubSubTopicDoesNotExistException- - If the topic does not exist.PubSubClientRetriableException- - If the operation fails due to transient reasons.PubSubClientException- - If the operation fails due to other reasons.
-
sendMessage
public CompletableFuture<PubSubProduceResult> sendMessage(PubSubTopicPartition pubSubTopicPartition, byte[] keyBytes, byte[] valueBytes, PubSubMessageHeaders pubsubMessageHeaders, PubSubProducerCallback pubsubProducerCallback) Description copied from interface:PubSubProducerAdapterSends a message to a PubSub topic asynchronously and returns aCompletableFuturerepresenting the result of the produce operation.- Specified by:
sendMessagein interfacePubSubProducerAdapter- Parameters:
pubSubTopicPartition- The partition of the PubSub topic to which the message will be sent.keyBytes- The key associated with the message, used for partitioning and message retrieval, represented as a byte array.valueBytes- The message payload to be sent to the PubSub topic, represented as a byte array.pubsubMessageHeaders- Additional headers to be included with the message, encapsulated in aPubSubMessageHeadersobject.pubsubProducerCallback- An optional callback to handle the result of the produce operation, encapsulated in aPubSubProducerCallbackobject.- Returns:
- A
CompletableFuturerepresenting the result of the produce operation, encapsulated in aPubSubProduceResultobject.
-
flush
public void flush()- Specified by:
flushin interfacePubSubProducerAdapter
-
close
public void close(long closeTimeOutMs) - Specified by:
closein interfacePubSubProducerAdapter
-
getMeasurableProducerMetrics
- Specified by:
getMeasurableProducerMetricsin interfacePubSubProducerAdapter
-
getBrokerAddress
- Specified by:
getBrokerAddressin interfacePubSubProducerAdapter
-