ProcessingResult.java


Overview

`ProcessingResult.java` defines the `ProcessingResult` class, a simple immutable data holder used within the Apache Camel Kafka component to represent the outcome of processing one or more Kafka consumer records. It encapsulates key information about the processing status, including whether processing failed, whether a "break on error" condition was triggered, and metadata about the Kafka topic, partition, and offset associated with the processed records.

This class primarily serves as a communication object within the Kafka consumer processing workflow, enabling other components to react accordingly based on success or failure states and consumer position tracking.


Class: ProcessingResult

Purpose

`ProcessingResult` captures the result of processing messages consumed from Kafka topics. It provides:

Properties

Property

Type

Description

`breakOnErrorHit`

boolean

Indicates if processing stopped due to a break-on-error condition.

`failed`

boolean

Indicates if processing of the message(s) failed.

`topic`

String

Kafka topic name associated with the processed record. May be `null` if unspecified.

`partition`

int

Partition number of the Kafka topic.

`offset`

long

Offset of the Kafka message in the partition.

Constructors

ProcessingResult(boolean breakOnErrorHit, boolean failed)

Creates a `ProcessingResult` instance without specifying topic, partition, or offset.

ProcessingResult result = new ProcessingResult(true, false);

ProcessingResult(boolean breakOnErrorHit, boolean failed, String topic, int partition, long offset)

Creates a `ProcessingResult` instance with detailed Kafka record metadata.

ProcessingResult detailedResult = new ProcessingResult(false, true, "my-topic", 2, 12345L);

Methods

Method

Return Type

Description

`isBreakOnErrorHit()`

boolean

Returns whether the processing hit a break-on-error condition.

`isFailed()`

boolean

Returns whether the processing failed.

`getTopic()`

String

Returns the Kafka topic name associated with this result.

`getPartition()`

int

Returns the partition number of the Kafka topic.

`getOffset()`

long

Returns the offset of the consumer record in the partition.

`static newUnprocessed()`

ProcessingResult

Returns a singleton instance representing an unprocessed result (`breakOnErrorHit=false`, `failed=false`, no topic info).

Usage Example

// Create a processing result indicating failure and break on error
ProcessingResult failureResult = new ProcessingResult(true, true, "orders-topic", 1, 1024L);

if (failureResult.isFailed()) {
    // Handle failure logic here
    System.out.println("Processing failed for topic: " + failureResult.getTopic());
}

// Obtain an unprocessed result singleton
ProcessingResult unprocessed = ProcessingResult.newUnprocessed();

Implementation Details


Interaction with Other Components


Visual Diagram: Class Structure

classDiagram
    class ProcessingResult {
        -boolean breakOnErrorHit
        -boolean failed
        -String topic
        -int partition
        -long offset
        +ProcessingResult(breakOnErrorHit: boolean, failed: boolean)
        +ProcessingResult(breakOnErrorHit: boolean, failed: boolean, topic: String, partition: int, offset: long)
        +isBreakOnErrorHit(): boolean
        +isFailed(): boolean
        +getTopic(): String
        +getPartition(): int
        +getOffset(): long
        +static newUnprocessed(): ProcessingResult
    }

Summary

`ProcessingResult.java` is a concise, immutable data carrier class that encapsulates processing outcomes for Kafka consumer records in Apache Camel. It provides essential flags and Kafka metadata that enable error handling, flow control, and offset management during Kafka message consumption. Its design prioritizes simplicity, thread safety, and ease of use in the broader Kafka processing workflow.