All Downloads are FREE. Search and download functionalities are using the official Maven repository.

reactor.kafka.sender.TransactionManager Maven / Gradle / Ivy

/*
 * Copyright (c) 2016-2022 VMware Inc. or its affiliates, All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package reactor.kafka.sender;

import org.apache.kafka.clients.consumer.ConsumerGroupMetadata;
import org.apache.kafka.clients.consumer.OffsetAndMetadata;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.common.TopicPartition;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Scheduler;

import java.util.Map;
import java.util.function.Consumer;

public interface TransactionManager {

    /**
     * Begins a new transaction. See {@link KafkaProducer#beginTransaction()} for more details.
     * No other operations may be performed on this sender while this begin operation is in progress.
     * 

* Example usage: *

     * {@code
     * transactionManager = kafkaSender.transactionManager();
     * transactionManager.begin()
     *                   .then(kafkaSender.send(outboundFlux))
     *                   .then(transactionManager.commit());
     * }
     * 
* @return empty Mono that completes when the transaction has started */ Mono begin(); /** * Sends provided offsets to the consumer offsets topic. Offsets are updated within the current transaction. * See {@link KafkaProducer#sendOffsetsToTransaction(Map, String)} for details on updating consumer offsets * within a transaction. * * @param offsets Consumer offsets to update * @param consumerGroupId The consumer group id for which offsets are updated * @return empty {@link Mono} that completes when the offsets have been sent to the consumer offsets topic. * The offsets will be committed when the current transaction is committed. * @deprecated in favor of #sendOffsets(Map, ConsumerGroupMetadata) */ @Deprecated Mono sendOffsets(Map offsets, String consumerGroupId); /** * Sends provided offsets to the consumer offsets topic. Offsets are updated within the current transaction. * See {@link KafkaProducer#sendOffsetsToTransaction(Map, ConsumerGroupMetadata)} for details on updating consumer * offsets within a transaction. * * @param offsets Consumer offsets to update * @param metadata The consumer group metadata * @return empty {@link Mono} that completes when the offsets have been sent to the consumer offsets topic. * The offsets will be committed when the current transaction is committed. * @since 1.3.9 */ default Mono sendOffsets(Map offsets, ConsumerGroupMetadata metadata) { return sendOffsets(offsets, metadata.groupId()); } /** * Commits the current transaction. See {@link KafkaProducer#commitTransaction()} for details. * @return empty {@link Mono} that completes when the transaction is committed. */ Mono commit(); /** * Aborts the current transaction. See {@link KafkaProducer#abortTransaction()} for details. * @return empty {@link Mono} that completes when the transaction is aborted. */ Mono abort(); /** * Returns the scheduler associated with this transaction instance. All transactional * operations on this transaction and the parent {@link KafkaSender} are published on * this scheduler. This scheduler is configured using {@link SenderOptions#scheduler(Scheduler)} * and it must be single threaded. * * @return the scheduler associated with this transaction instance. */ Scheduler scheduler(); /** * A callback to indicate a commit or rollback has completed, true for commit. * @param txComplete the commitComplete to set. * @return the manager; * @since 1.3.12 */ default TransactionManager transactionComplete(Consumer txComplete) { return this; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy