Class KafkaTransactionsImpl<T>
- All Implemented Interfaces:
io.smallrye.reactive.messaging.EmitterType,KafkaTransactions<T>,io.smallrye.reactive.messaging.MessagePublisherProvider<T>,io.smallrye.reactive.messaging.MutinyEmitter<T>
-
Field Summary
Fields inherited from class io.smallrye.reactive.messaging.providers.extension.AbstractEmitter
internal, name, NO_SUBSCRIBER_EXCEPTION, publisher, synchronousFailure -
Constructor Summary
ConstructorsConstructorDescriptionKafkaTransactionsImpl(io.smallrye.reactive.messaging.EmitterConfiguration config, long defaultBufferSize, KafkaClientService clientService) -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanboolean<R> io.smallrye.mutiny.Uni<R> withTransaction(io.smallrye.reactive.messaging.kafka.api.IncomingKafkaRecordBatchMetadata<?, ?> metadata, Function<TransactionalEmitter<T>, io.smallrye.mutiny.Uni<R>> work) Produce records in a Kafka transaction, by processing the given incoming record batch exactly-once.<R> io.smallrye.mutiny.Uni<R> withTransaction(io.smallrye.reactive.messaging.kafka.api.IncomingKafkaRecordMetadata<?, ?> metadata, Function<TransactionalEmitter<T>, io.smallrye.mutiny.Uni<R>> work) Produce records in a Kafka transaction, by processing the given incoming record exactly-once.<R> io.smallrye.mutiny.Uni<R> withTransaction(Function<TransactionalEmitter<T>, io.smallrye.mutiny.Uni<R>> work) Produce records in a Kafka transaction.<R> io.smallrye.mutiny.Uni<R> withTransaction(org.eclipse.microprofile.reactive.messaging.Message<?> message, Function<TransactionalEmitter<T>, io.smallrye.mutiny.Uni<R>> work) Produce records in a Kafka transaction, by processing the given message exactly-once.<R> RwithTransactionAndAwait(io.smallrye.reactive.messaging.kafka.api.IncomingKafkaRecordBatchMetadata<?, ?> metadata, Function<TransactionalEmitter<T>, io.smallrye.mutiny.Uni<R>> work) Produce records in a Kafka transaction processing the given incoming record batch exactly-once, blocking the calling thread until the transaction completes.<R> RwithTransactionAndAwait(io.smallrye.reactive.messaging.kafka.api.IncomingKafkaRecordMetadata<?, ?> metadata, Function<TransactionalEmitter<T>, io.smallrye.mutiny.Uni<R>> work) Produce records in a Kafka transaction processing the given incoming record exactly-once, blocking the calling thread until the transaction completes.<R> RwithTransactionAndAwait(Function<TransactionalEmitter<T>, io.smallrye.mutiny.Uni<R>> work) Produce records in a Kafka transaction, blocking the calling thread until the transaction completes.Methods inherited from class io.smallrye.reactive.messaging.providers.extension.MutinyEmitterImpl
send, send, sendAndAwait, sendAndForget, sendMessage, sendMessageAndAwait, sendMessageAndForgetMethods inherited from class io.smallrye.reactive.messaging.providers.extension.AbstractEmitter
complete, emit, error, getPublisher, hasRequests, isCancelled, verifyMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.smallrye.reactive.messaging.kafka.transactions.KafkaTransactions
withTransactionAndAckMethods inherited from interface io.smallrye.reactive.messaging.MutinyEmitter
complete, error, hasRequests, isCancelled
-
Constructor Details
-
KafkaTransactionsImpl
public KafkaTransactionsImpl(io.smallrye.reactive.messaging.EmitterConfiguration config, long defaultBufferSize, KafkaClientService clientService)
-
-
Method Details
-
isFatalError
-
isTransactionInProgress
public boolean isTransactionInProgress()- Specified by:
isTransactionInProgressin interfaceKafkaTransactions<T>- Returns:
trueif a transaction is in progress.
-
withTransaction
@CheckReturnValue public <R> io.smallrye.mutiny.Uni<R> withTransaction(Function<TransactionalEmitter<T>, io.smallrye.mutiny.Uni<R>> work) Description copied from interface:KafkaTransactionsProduce records in a Kafka transaction.The given processing function receives a
TransactionalEmitterfor producing records, and returns aUnithat will provide the result for a successful transaction.If this method is called on a Vert.x context, the processing function is also called on that context. Otherwise, it is called on the sending thread of the producer.
If the processing completes successfully, the producer is flushed and the transaction is committed. If the processing throws an exception, returns a failing
Uni, or marks theTransactionalEmitterfor abort, the transaction is aborted.- Specified by:
withTransactionin interfaceKafkaTransactions<T>- Type Parameters:
R- the return type- Parameters:
work- the processing function for producing records.- Returns:
- the
Unirepresenting the result of the transaction. If the transaction completes successfully, it will complete with the item returned from the work function. If the transaction completes with failure, it will fail with the reason.
-
withTransactionAndAwait
public <R> R withTransactionAndAwait(Function<TransactionalEmitter<T>, io.smallrye.mutiny.Uni<R>> work) Description copied from interface:KafkaTransactionsProduce records in a Kafka transaction, blocking the calling thread until the transaction completes.This is a synchronous variant of
KafkaTransactions.withTransaction(Function), intended for use in blocking contexts such as REST endpoints running on worker threads or@Blockingannotated methods.Must not be called on a Vert.x event loop thread.
- Specified by:
withTransactionAndAwaitin interfaceKafkaTransactions<T>- Type Parameters:
R- the return type- Parameters:
work- the processing function for producing records.- Returns:
- the result of the transaction.
- See Also:
-
withTransaction
@CheckReturnValue public <R> io.smallrye.mutiny.Uni<R> withTransaction(org.eclipse.microprofile.reactive.messaging.Message<?> message, Function<TransactionalEmitter<T>, io.smallrye.mutiny.Uni<R>> work) Description copied from interface:KafkaTransactionsProduce records in a Kafka transaction, by processing the given message exactly-once.If the processing completes successfully, before committing the transaction, the topic partition offsets of the given message will be committed to the transaction. If the processing needs to abort, after aborting the transaction, the consumer's position is reset to the last committed offset, effectively resuming the consumption from that offset.
- Specified by:
withTransactionin interfaceKafkaTransactions<T>- Parameters:
message- the incoming Kafka message expected to contain a metadataIncomingKafkaRecordBatchMetadataorIncomingKafkaRecordMetadata.work- the processing function for producing records.- Returns:
- the
Unirepresenting the result of the transaction. If the transaction completes successfully, it will complete with the item returned from the work function. If the transaction completes with failure, it will fail with the reason.
-
withTransaction
@CheckReturnValue public <R> io.smallrye.mutiny.Uni<R> withTransaction(io.smallrye.reactive.messaging.kafka.api.IncomingKafkaRecordMetadata<?, ?> metadata, Function<TransactionalEmitter<T>, io.smallrye.mutiny.Uni<R>> work) Description copied from interface:KafkaTransactionsProduce records in a Kafka transaction, by processing the given incoming record exactly-once.If the processing completes successfully, before committing the transaction, the topic partition offset of the given record metadata will be committed to the transaction. If the processing needs to abort, after aborting the transaction, the consumer's position is reset to the last committed offset, effectively resuming the consumption from that offset.
- Specified by:
withTransactionin interfaceKafkaTransactions<T>- Parameters:
metadata- the incoming Kafka record metadata.work- the processing function for producing records.- Returns:
- the
Unirepresenting the result of the transaction.
-
withTransactionAndAwait
public <R> R withTransactionAndAwait(io.smallrye.reactive.messaging.kafka.api.IncomingKafkaRecordMetadata<?, ?> metadata, Function<TransactionalEmitter<T>, io.smallrye.mutiny.Uni<R>> work) Description copied from interface:KafkaTransactionsProduce records in a Kafka transaction processing the given incoming record exactly-once, blocking the calling thread until the transaction completes.This is a synchronous variant of
KafkaTransactions.withTransaction(IncomingKafkaRecordMetadata, Function). Must not be called on a Vert.x event loop thread.- Specified by:
withTransactionAndAwaitin interfaceKafkaTransactions<T>- Type Parameters:
R- the return type- Parameters:
metadata- the incoming Kafka record metadata.work- the processing function for producing records.- Returns:
- the result of the transaction.
- See Also:
-
withTransaction
@CheckReturnValue public <R> io.smallrye.mutiny.Uni<R> withTransaction(io.smallrye.reactive.messaging.kafka.api.IncomingKafkaRecordBatchMetadata<?, ?> metadata, Function<TransactionalEmitter<T>, io.smallrye.mutiny.Uni<R>> work) Description copied from interface:KafkaTransactionsProduce records in a Kafka transaction, by processing the given incoming record batch exactly-once.If the processing completes successfully, before committing the transaction, the topic partition offsets of the given batch metadata will be committed to the transaction. If the processing needs to abort, after aborting the transaction, the consumer's position is reset to the last committed offset, effectively resuming the consumption from that offset.
- Specified by:
withTransactionin interfaceKafkaTransactions<T>- Parameters:
metadata- the incoming Kafka record batch metadata.work- the processing function for producing records.- Returns:
- the
Unirepresenting the result of the transaction.
-
withTransactionAndAwait
public <R> R withTransactionAndAwait(io.smallrye.reactive.messaging.kafka.api.IncomingKafkaRecordBatchMetadata<?, ?> metadata, Function<TransactionalEmitter<T>, io.smallrye.mutiny.Uni<R>> work) Description copied from interface:KafkaTransactionsProduce records in a Kafka transaction processing the given incoming record batch exactly-once, blocking the calling thread until the transaction completes.This is a synchronous variant of
KafkaTransactions.withTransaction(IncomingKafkaRecordBatchMetadata, Function). Must not be called on a Vert.x event loop thread.- Specified by:
withTransactionAndAwaitin interfaceKafkaTransactions<T>- Type Parameters:
R- the return type- Parameters:
metadata- the incoming Kafka record batch metadata.work- the processing function for producing records.- Returns:
- the result of the transaction.
- See Also:
-