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>

    public class KafkaTransactionsImpl<T>
    extends MutinyEmitterImpl<T>
    implements KafkaTransactions<T>
    • Constructor Detail

      • KafkaTransactionsImpl

        public KafkaTransactionsImpl​(io.smallrye.reactive.messaging.EmitterConfiguration config,
                                     long defaultBufferSize,
                                     KafkaClientService clientService)
    • Method Detail

      • withTransaction

        @CheckReturnValue
        public <R> io.smallrye.mutiny.Uni<R> withTransaction​(Function<TransactionalEmitter<T>,​io.smallrye.mutiny.Uni<R>> work)
        Description copied from interface: KafkaTransactions
        Produce records in a Kafka transaction.

        The given processing function receives a TransactionalEmitter for producing records, and returns a Uni that 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 the TransactionalEmitter for abort, the transaction is aborted.

        Specified by:
        withTransaction in interface KafkaTransactions<T>
        Type Parameters:
        R - the return type
        Parameters:
        work - the processing function for producing records.
        Returns:
        the Uni representing 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​(org.eclipse.microprofile.reactive.messaging.Message<?> message,
                                                             Function<TransactionalEmitter<T>,​io.smallrye.mutiny.Uni<R>> work)
        Description copied from interface: KafkaTransactions
        Produce 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:
        withTransaction in interface KafkaTransactions<T>
        Parameters:
        message - the incoming Kafka message expected to contain a metadata IncomingKafkaRecordBatchMetadata or IncomingKafkaRecordMetadata.
        work - the processing function for producing records.
        Returns:
        the Uni representing 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.