Class ReactiveKafkaProducer<K,V>
java.lang.Object
io.smallrye.reactive.messaging.kafka.impl.ReactiveKafkaProducer<K,V>
- All Implemented Interfaces:
KafkaProducer<K,V>
-
Constructor Summary
ConstructorsConstructorDescriptionReactiveKafkaProducer(KafkaConnectorOutgoingConfiguration config, jakarta.enterprise.inject.Instance<SerializationFailureHandler<?>> serializationFailureHandlers, jakarta.enterprise.inject.Instance<org.apache.kafka.clients.producer.ProducerInterceptor<?, ?>> producerInterceptors, Consumer<Throwable> reportFailure, BiConsumer<org.apache.kafka.clients.producer.Producer<?, ?>, Map<String, Object>> onProducerCreated) ReactiveKafkaProducer(Map<String, Object> kafkaConfiguration, String channel, int closeTimeout, boolean lazyClient, org.apache.kafka.clients.producer.ProducerInterceptor<K, V> interceptor, SerializationFailureHandler<K> keySerializationFailureHandler, SerializationFailureHandler<V> valueSerializationFailureHandler, BiConsumer<org.apache.kafka.clients.producer.Producer<?, ?>, Map<String, Object>> onProducerCreated) -
Method Summary
Modifier and TypeMethodDescriptionio.smallrye.mutiny.Uni<Void>io.smallrye.mutiny.Uni<Void>voidclose()Close the producer clientio.smallrye.mutiny.Uni<Void>io.smallrye.mutiny.Uni<Void>flush()Sends all buffered records immediately.io.smallrye.mutiny.Uni<Void>io.smallrye.mutiny.Uni<List<org.apache.kafka.common.PartitionInfo>>partitionsFor(String topic) Returns a list of partition metadata for given topic.io.smallrye.mutiny.Uni<Void>runOnSendingThread(Consumer<org.apache.kafka.clients.producer.Producer<K, V>> action) Runs an action on the sending thread.<T> io.smallrye.mutiny.Uni<T>runOnSendingThread(Function<org.apache.kafka.clients.producer.Producer<K, V>, T> action) Runs an action on the sending thread.io.smallrye.mutiny.Uni<org.apache.kafka.clients.producer.RecordMetadata>Send a record to a topic.io.smallrye.mutiny.Uni<Void>sendOffsetsToTransaction(Map<org.apache.kafka.common.TopicPartition, org.apache.kafka.clients.consumer.OffsetAndMetadata> offsets, org.apache.kafka.clients.consumer.ConsumerGroupMetadata groupMetadata) unwrap()
-
Constructor Details
-
ReactiveKafkaProducer
public ReactiveKafkaProducer(KafkaConnectorOutgoingConfiguration config, jakarta.enterprise.inject.Instance<SerializationFailureHandler<?>> serializationFailureHandlers, jakarta.enterprise.inject.Instance<org.apache.kafka.clients.producer.ProducerInterceptor<?, ?>> producerInterceptors, Consumer<Throwable> reportFailure, BiConsumer<org.apache.kafka.clients.producer.Producer<?, ?>, Map<String, Object>> onProducerCreated) -
ReactiveKafkaProducer
public ReactiveKafkaProducer(Map<String, Object> kafkaConfiguration, String channel, int closeTimeout, boolean lazyClient, org.apache.kafka.clients.producer.ProducerInterceptor<K, V> interceptor, SerializationFailureHandler<K> keySerializationFailureHandler, SerializationFailureHandler<V> valueSerializationFailureHandler, BiConsumer<org.apache.kafka.clients.producer.Producer<?, ?>, Map<String, Object>> onProducerCreated)
-
-
Method Details
-
getClientId
-
runOnSendingThread
@CheckReturnValue public <T> io.smallrye.mutiny.Uni<T> runOnSendingThread(Function<org.apache.kafka.clients.producer.Producer<K, V>, T> action) Description copied from interface:KafkaProducerRuns an action on the sending thread.The action is a function taking as parameter the
Producerand that returns a result (potentiallynull). The producedUniemits the returned result when the action completes. If the action throws an exception, the producedUniemits the exception as failure.If the action does not return a result, use
KafkaProducer.runOnSendingThread(java.util.function.Consumer).- Specified by:
runOnSendingThreadin interfaceKafkaProducer<K,V> - Type Parameters:
T- the type of result, can beVoid- Parameters:
action- the action to execute, must not benull- Returns:
- the Uni emitting the result or the failure when the action completes.
-
runOnSendingThread
@CheckReturnValue public io.smallrye.mutiny.Uni<Void> runOnSendingThread(Consumer<org.apache.kafka.clients.producer.Producer<K, V>> action) Description copied from interface:KafkaProducerRuns an action on the sending thread.The action is a consumer receiving the
Producer. The producedUniemitsnullwhen the action completes. If the action throws an exception, the producedUniemits the exception as failure.- Specified by:
runOnSendingThreadin interfaceKafkaProducer<K,V> - Parameters:
action- the action, must not benull- Returns:
- the Uni emitting
nullor the failure when the action completes.
-
send
@CheckReturnValue public io.smallrye.mutiny.Uni<org.apache.kafka.clients.producer.RecordMetadata> send(org.apache.kafka.clients.producer.ProducerRecord<K, V> record) Description copied from interface:KafkaProducerSend a record to a topic. The returnedUnicompletes withRecordMetadatawhen the send has been acknowledged, or with an exception in case of an error.- Specified by:
sendin interfaceKafkaProducer<K,V>
-
flush
Description copied from interface:KafkaProducerSends all buffered records immediately. The returnedUnicompletes when all requests belonging to the buffered records complete. In other words, when the returnedUnicompletes, all previousKafkaProducer.send(ProducerRecord)operations are known to be complete as well. No guarantee is made about the completion of records sent afterflushwas called.- Specified by:
flushin interfaceKafkaProducer<K,V>
-
partitionsFor
@CheckReturnValue public io.smallrye.mutiny.Uni<List<org.apache.kafka.common.PartitionInfo>> partitionsFor(String topic) Description copied from interface:KafkaProducerReturns a list of partition metadata for given topic.- Specified by:
partitionsForin interfaceKafkaProducer<K,V>
-
initTransactions
- Specified by:
initTransactionsin interfaceKafkaProducer<K,V> - Returns:
- the Uni emitting
nullwhen theProducer.initTransactions()executes.
-
beginTransaction
- Specified by:
beginTransactionin interfaceKafkaProducer<K,V> - Returns:
- the Uni emitting
nullwhen theProducer.beginTransaction()executes.
-
commitTransaction
- Specified by:
commitTransactionin interfaceKafkaProducer<K,V> - Returns:
- the Uni emitting
nullwhen theProducer.commitTransaction()executes.
-
abortTransaction
- Specified by:
abortTransactionin interfaceKafkaProducer<K,V> - Returns:
- the Uni emitting
nullwhen theProducer.abortTransaction()executes.
-
sendOffsetsToTransaction
@CheckReturnValue public io.smallrye.mutiny.Uni<Void> sendOffsetsToTransaction(Map<org.apache.kafka.common.TopicPartition, org.apache.kafka.clients.consumer.OffsetAndMetadata> offsets, org.apache.kafka.clients.consumer.ConsumerGroupMetadata groupMetadata) - Specified by:
sendOffsetsToTransactionin interfaceKafkaProducer<K,V> - Parameters:
offsets- topic partition offsets to commit into transactiongroupMetadata- consumer group metadata of the exactly-once consumer- Returns:
- the Uni emitting
nullwhen theProducer.sendOffsetsToTransaction(Map, ConsumerGroupMetadata)executes.
-
get
-
unwrap
- Specified by:
unwrapin interfaceKafkaProducer<K,V> - Returns:
- the underlying producer. Be aware that to use it you needs to be on the sending thread.
-
configuration
- Specified by:
configurationin interfaceKafkaProducer<K,V> - Returns:
- Kafka producer configuration
-
close
public void close()Description copied from interface:KafkaProducerClose the producer client- Specified by:
closein interfaceKafkaProducer<K,V>
-