KafkaBreakOnFirstErrorWithBatchUsingKafkaManualCommitRetryIT.java


Overview

`KafkaBreakOnFirstErrorWithBatchUsingKafkaManualCommitRetryIT.java` is an integration test class within the Apache Camel Kafka component suite. This test specifically validates the **breakOnFirstError** functionality when consuming Kafka messages in batches, combined with manual offset commit management and retry semantics.

The test demonstrates how to:

This class extends a base Kafka test support class and contains a Kafka route configured for manual commit and error handling, along with a test method verifying retry behavior when an error occurs.


Class: KafkaBreakOnFirstErrorWithBatchUsingKafkaManualCommitRetryIT

Description

This JUnit 5 test class verifies that Kafka consumer routes configured with [breakOnFirstError](/projects/289/68663) and manual commit correctly retry messages that fail processing within a batch, without committing their offsets until successful processing.

Important Annotations

Constants

Constant

Type

Description

`ROUTE_ID`

String

Identifier for the Camel route under test.

`TOPIC`

String

Kafka topic name used in this test.

Fields

Field Name

Type

Description

`to`

`MockEndpoint`

Mock endpoint to capture and assert messages from the route.

`producer`

org.apache.kafka.clients.producer.KafkaProducer

Kafka producer instance used to send test messages.


Lifecycle Methods

before()

after()


Test Method

kafkaBreakOnFirstErrorBasicCapabilityRetry()


Route Definition

createRouteBuilder()


Private Helper Methods

publishMessagesToKafka()

doCommitOffset(Exchange exchange)

ifIsPayloadWithErrorThrowException(Exchange exchange)


Implementation Details & Algorithms


Interaction with Other Components


Usage Example

This test class is primarily for automated integration testing within the Apache Camel Kafka component. To run the test:

  1. Ensure the Kafka environment and dependencies are available.

  2. Run the test via JUnit 5 compatible test runner.

  3. Observe that messages causing errors are retried, and that no offsets are committed for failed messages.


Class Diagram

classDiagram
    class KafkaBreakOnFirstErrorWithBatchUsingKafkaManualCommitRetryIT {
        - static final String ROUTE_ID
        - static final String TOPIC
        - static final Logger LOG
        - MockEndpoint to
        - KafkaProducer<String,String> producer
        + void before()
        + void after()
        + void kafkaBreakOnFirstErrorBasicCapabilityRetry()
        + RouteBuilder createRouteBuilder()
        - void publishMessagesToKafka()
        - void doCommitOffset(Exchange)
        - void ifIsPayloadWithErrorThrowException(Exchange)
    }
    KafkaBreakOnFirstErrorWithBatchUsingKafkaManualCommitRetryIT ..|> BaseKafkaTestSupport

Summary

`KafkaBreakOnFirstErrorWithBatchUsingKafkaManualCommitRetryIT.java` is a focused integration test validating Kafka batch message consumption with manual offset commit and "break on first error" semantics in Camel routes. It helps ensure that messages causing exceptions trigger retries without prematurely committing offsets, thus preserving message processing guarantees in Kafka-Camel integrations.