CamelKafkaUtil.java

Overview

`CamelKafkaUtil.java` is a utility class within the Apache Camel Kafka component test utilities package (`org.apache.camel.component.kafka.testutil`). Its primary purpose is to provide helper methods related to Kafka message processing and logging inside Camel Kafka integration tests.

Specifically, it contains a static method to build a detailed log message describing Kafka messages consumed by Camel routes. This facilitates debugging and monitoring by producing consistent, informative log output including topic, partition, offset, key, and optionally the message body.

This class is designed as a non-instantiable utility class, indicated by a private constructor and static methods only.


Class Summary

CamelKafkaUtil

A final utility class providing Kafka-related helper methods for logging messages in Apache Camel Kafka tests.


Implementation Details


Interaction with Other System Components


Mermaid Diagram

The following flowchart illustrates the main function and the flow of information inside `CamelKafkaUtil.java`:

flowchart TD
    A[buildKafkaLogMessage] --> B{Is msg\nnon-null?}
    B -- Yes --> C[Append msg + newline]
    B -- No --> D[Skip msg]

    C & D --> E[Append "Message consumed from" + topic header + newline]
    E --> F[Append "The Partition:Offset is" + partition + ":" + offset + newline]
    F --> G[Append "The Key is" + key header]

    G --> H{includeBody?}
    H -- Yes --> I[Append newline + message body as String]
    H -- No --> J[Skip body]

    I & J --> K[Return constructed log String]

Summary

`CamelKafkaUtil.java` provides a focused utility method to format Kafka message details from Camel exchanges into readable log messages, greatly aiding in testing, debugging, and monitoring Kafka interactions within Apache Camel routes. Its simple yet effective design leverages Camel Kafka headers and supports optional inclusion of message bodies, aligning with common testing needs in Camel Kafka integration projects.