KafkaConsumerFatalException.java

Overview

The [KafkaConsumerFatalException.java](/projects/289/68528) file defines a custom exception class named `KafkaConsumerFatalException` in the Apache Camel Kafka component. This exception represents a fatal error condition in the Kafka consumer lifecycle within the Camel integration framework. Specifically, it is thrown when the Kafka consumer fails to be created or subscribed to Kafka brokers within a configured backoff period, leading to the termination of the Kafka consumer thread. The key implication of this exception is that the Kafka consumer will not attempt to recover automatically; recovery requires manual intervention such as restarting the Camel route or the entire application.

This class extends `RuntimeException` and primarily serves as a signal to the Camel Kafka component and its users that a non-recoverable error has occurred in Kafka consumption, enforcing fail-fast behavior in such situations.


Class: KafkaConsumerFatalException

Package

`org.apache.camel.component.kafka`

Inheritance

Description

`KafkaConsumerFatalException` is a runtime exception used to indicate fatal errors related to Kafka consumer initialization or subscription failures within the Camel Kafka component.


Constructor

public KafkaConsumerFatalException(String message, Throwable cause)

Parameters:

Behavior:

Usage Example:

try {
    // Code attempting to create and subscribe Kafka consumer
    kafkaConsumer.subscribe(Collections.singleton("my-topic"));
} catch (Exception e) {
    throw new KafkaConsumerFatalException("Failed to create or subscribe Kafka consumer after retries", e);
}

This example illustrates how the exception can be thrown to indicate a fatal failure requiring the termination of the consumer thread.


Implementation Details


Interaction with Other Components

This mechanism ensures that persistent Kafka connectivity issues do not lead to uncontrolled retry loops, thereby protecting system stability.


Visual Diagram

classDiagram
    class KafkaConsumerFatalException {
        +KafkaConsumerFatalException(message: String, cause: Throwable)
    }
    KafkaConsumerFatalException --|> RuntimeException

Summary

This file plays a critical role in error handling for Kafka integration in Camel, enforcing fail-fast semantics on severe Kafka consumer failures.