Class ReactiveKafkaProducer<K,V>
- java.lang.Object
-
- io.smallrye.reactive.messaging.kafka.impl.ReactiveKafkaProducer<K,V>
-
- All Implemented Interfaces:
KafkaProducer<K,V>
public class ReactiveKafkaProducer<K,V> extends Object implements KafkaProducer<K,V>
-
-
Constructor Summary
Constructors Constructor Description ReactiveKafkaProducer(KafkaConnectorOutgoingConfiguration config, javax.enterprise.inject.Instance<SerializationFailureHandler<?>> serializationFailureHandlers)
ReactiveKafkaProducer(Map<String,Object> kafkaConfiguration, String channel, int closeTimeout, SerializationFailureHandler<K> keySerializationFailureHandler, SerializationFailureHandler<V> valueSerializationFailureHandler)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Map<String,?>
configuration()
io.smallrye.mutiny.Uni<Void>
flush()
Sends all buffered records immediately.String
get(String attribute)
String
getClientId()
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(org.apache.kafka.clients.producer.ProducerRecord<K,V> record)
Send a record to a topic.org.apache.kafka.clients.producer.Producer<K,V>
unwrap()
-
-
-
Constructor Detail
-
ReactiveKafkaProducer
public ReactiveKafkaProducer(KafkaConnectorOutgoingConfiguration config, javax.enterprise.inject.Instance<SerializationFailureHandler<?>> serializationFailureHandlers)
-
ReactiveKafkaProducer
public ReactiveKafkaProducer(Map<String,Object> kafkaConfiguration, String channel, int closeTimeout, SerializationFailureHandler<K> keySerializationFailureHandler, SerializationFailureHandler<V> valueSerializationFailureHandler)
-
-
Method Detail
-
getClientId
public String 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:KafkaProducer
Runs an action on the sending thread.The action is a function taking as parameter the
Producer
and that returns a result (potentiallynull
). The producedUni
emits the returned result when the action completes. If the action throws an exception, the producedUni
emits the exception as failure.If the action does not return a result, use
KafkaProducer.runOnSendingThread(java.util.function.Consumer)
.- Specified by:
runOnSendingThread
in 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:KafkaProducer
Runs an action on the sending thread.The action is a consumer receiving the
Producer
. The producedUni
emitsnull
when the action completes. If the action throws an exception, the producedUni
emits the exception as failure.- Specified by:
runOnSendingThread
in interfaceKafkaProducer<K,V>
- Parameters:
action
- the action, must not benull
- Returns:
- the Uni emitting
null
or 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:KafkaProducer
Send a record to a topic. The returnedUni
completes withRecordMetadata
when the send has been acknowledged, or with an exception in case of an error.- Specified by:
send
in interfaceKafkaProducer<K,V>
-
flush
@CheckReturnValue public io.smallrye.mutiny.Uni<Void> flush()
Description copied from interface:KafkaProducer
Sends all buffered records immediately. The returnedUni
completes when all requests belonging to the buffered records complete. In other words, when the returnedUni
completes, all previousKafkaProducer.send(ProducerRecord)
operations are known to be complete as well. No guarantee is made about the completion of records sent afterflush
was called.- Specified by:
flush
in interfaceKafkaProducer<K,V>
-
partitionsFor
@CheckReturnValue public io.smallrye.mutiny.Uni<List<org.apache.kafka.common.PartitionInfo>> partitionsFor(String topic)
Description copied from interface:KafkaProducer
Returns a list of partition metadata for given topic.- Specified by:
partitionsFor
in interfaceKafkaProducer<K,V>
-
unwrap
public org.apache.kafka.clients.producer.Producer<K,V> unwrap()
- Specified by:
unwrap
in interfaceKafkaProducer<K,V>
- Returns:
- the underlying producer. Be aware that to use it you needs to be on the sending thread.
-
close
public void close()
-
-