RecordError.java

Overview

`RecordError.java` defines a simple data container class within the Apache Camel project, specifically in the Kafka resume processor module (`org.apache.camel.processor.resume.kafka`). This class encapsulates details about errors encountered when producing Kafka records. Its primary purpose is to hold both metadata of the Kafka record that failed and the exception that caused the failure, enabling easier error handling and diagnostics in the Kafka producer workflow.


Class: RecordError

Description

`RecordError` is a plain Java object (POJO) that stores information about a failed Kafka record production attempt. It holds two key pieces of data:

This class facilitates passing detailed error information up the call stack or to error handling logic, making it easier to log, analyze, or react to Kafka produce failures.

Package

org.apache.camel.processor.resume.kafka

Properties

Property

Type

Description

`recordMetadata`

`RecordMetadata`

Metadata about the Kafka record that failed.

`exception`

`Exception`

The exception thrown when producing the record failed.

Constructors

public RecordError(RecordMetadata recordMetadata, Exception exception)

Methods

getRecordMetadata

public RecordMetadata getRecordMetadata()

getException

public Exception getException()

Usage Example

import org.apache.kafka.clients.producer.RecordMetadata;
import org.apache.camel.processor.resume.kafka.RecordError;

try {
    // Code to produce Kafka record
} catch (Exception e) {
    RecordMetadata metadata = ...; // obtain metadata if available
    RecordError error = new RecordError(metadata, e);
    // Handle or log the error
    System.err.println("Failed to produce record at topic " + metadata.topic());
    e.printStackTrace();
}

This example shows how one might catch an exception during Kafka record production and encapsulate the failure details into a `RecordError` object for further processing.


Implementation Details


Interaction with Other Components


Class Diagram

classDiagram
    class RecordError {
        -RecordMetadata recordMetadata
        -Exception exception
        +RecordError(RecordMetadata recordMetadata, Exception exception)
        +RecordMetadata getRecordMetadata()
        +Exception getException()
    }

    RecordError --> RecordMetadata : uses

Summary

`RecordError.java` is a simple yet essential utility class designed to capture and convey detailed information about Kafka record production failures in Apache Camel's Kafka resume processor module. It encapsulates both the Kafka record metadata and the exception thrown, enabling effective error management and troubleshooting within Kafka producer workflows.