DefaultKafkaManualSyncCommit.java


Overview

`DefaultKafkaManualSyncCommit.java` is part of the Apache Camel Kafka component, specifically within the consumer package. This file defines the `DefaultKafkaManualSyncCommit` class, which provides a synchronous manual commit mechanism for Kafka message offsets during message consumption.

In Kafka consumer applications, committing offsets is crucial to keep track of processed messages and ensure at-least-once or exactly-once processing semantics. This class extends the base manual commit behavior and leverages a `CommitManager` to perform synchronous commits of Kafka message offsets, allowing explicit control over when the consumer acknowledges message processing completion.


Class: DefaultKafkaManualSyncCommit

Description

`DefaultKafkaManualSyncCommit` extends `DefaultKafkaManualCommit` and implements the `KafkaManualCommit` interface. It provides a synchronous commit operation for Kafka consumer offsets using the provided `CommitManager`. Unlike asynchronous commit strategies, this class ensures that the commit call blocks until the offset commit is confirmed, providing stronger guarantees about offset persistence.

Package

org.apache.camel.component.kafka.consumer

Superclass and Interfaces

Properties

Property

Type

Description

`commitManager`

`CommitManager`

Reference to a `CommitManager` responsible for handling commit operations.

Constructor

public DefaultKafkaManualSyncCommit(KafkaManualCommitFactory.CamelExchangePayload camelExchangePayload,
                                    KafkaManualCommitFactory.KafkaRecordPayload kafkaRecordPayload,
                                    CommitManager commitManager)

Methods

commit()

@Override
public void commit()
DefaultKafkaManualSyncCommit manualCommit = new DefaultKafkaManualSyncCommit(exchangePayload, recordPayload, commitManager);
manualCommit.commit();  // Synchronously commit the current message offset

Important Implementation Details


Interaction with Other Components


Class Diagram

classDiagram
    class DefaultKafkaManualCommit {
        +getPartition()
        +getRecordOffset()
    }
    class KafkaManualCommit {
        <<interface>>
        +commit()
    }
    class CommitManager {
        +forceCommit(partition, offset)
    }
    class DefaultKafkaManualSyncCommit {
        -commitManager: CommitManager
        +DefaultKafkaManualSyncCommit(camelExchangePayload, kafkaRecordPayload, commitManager)
        +commit()
    }

    DefaultKafkaManualSyncCommit --|> DefaultKafkaManualCommit
    DefaultKafkaManualSyncCommit ..|> KafkaManualCommit
    DefaultKafkaManualSyncCommit --> CommitManager : uses

Summary

The `DefaultKafkaManualSyncCommit` class is a concise, focused implementation providing synchronous manual offset commits in the Apache Camel Kafka consumer framework. It extends the base manual commit functionality and utilizes a `CommitManager` to enforce synchronous offset commits, ensuring that offset state is durably recorded before proceeding. This class plays an essential role in scenarios where precise control over offset commit timing is necessary to achieve desired processing guarantees within Kafka consumers integrated with Apache Camel.


**End of Documentation**