KafkaDevConsole.java


Overview

`KafkaDevConsole.java` is a developer console component integrated into the Apache Camel framework that provides real-time diagnostics and monitoring for Kafka consumers configured within Camel routes. Its primary purpose is to expose detailed runtime metrics about Kafka consumer fetch tasks, including thread states, last processed records, consumer group metadata, and optionally committed offset information directly fetched from Kafka brokers.

The class extends `AbstractDevConsole` and is annotated with `@DevConsole`, making it discoverable and usable within Camel's developer console infrastructure. This enables Camel users and operators to query Kafka consumer health and operational statistics either as plain text or JSON-formatted responses, facilitating easier debugging, health monitoring, and operational insight.


Detailed Class and Method Documentation

Class: KafkaDevConsole

Description

The `KafkaDevConsole` class provides two primary output formats for monitoring Kafka consumers:

  1. Textual output (doCallText) - Human-readable console text representation.

  2. JSON output (doCallJson) - Structured JSON representation useful for integrations or UI rendering.

It supports an option to include committed offsets (`"committed"`) that triggers synchronous fetching of committed offsets from Kafka brokers, enhancing the depth of monitoring.


Constants

Name

Type

Description

`COMMITTED_TIMEOUT`

`long`

Timeout in milliseconds (10,000ms) for fetching committed offsets from Kafka brokers

`COMMITTED`

`String`

Key option to include committed offsets in the output ("committed")


Constructor

KafkaDevConsole()

KafkaDevConsole console = new KafkaDevConsole();

Methods

protected String doCallText(Map<String, Object> options)

Map<String, Object> options = Map.of("committed", "true");
String metricsText = kafkaDevConsole.doCallText(options);
System.out.println(metricsText);

protected Map<String, Object> doCallJson(Map<String, Object> options)

Map<String, Object> options = Map.of("committed", "false");
Map<String, Object> jsonMetrics = kafkaDevConsole.doCallJson(options);
// Can be converted or serialized to JSON string for UI or API response

private static List<DefaultMetricsCollector.KafkaTopicPosition> fetchCommitOffsets(KafkaConsumer kc, DevConsoleMetricsCollector collector)


Important Implementation Details and Algorithms


Interactions with Other System Components


Usage Examples

Example 1: Fetch Kafka consumer metrics as text with committed offsets

KafkaDevConsole console = new KafkaDevConsole();
Map<String, Object> options = new HashMap<>();
options.put("committed", "true");
String metricsText = console.doCallText(options);
System.out.println(metricsText);

Example 2: Fetch Kafka consumer metrics as JSON without committed offsets

KafkaDevConsole console = new KafkaDevConsole();
Map<String, Object> options = new HashMap<>();
options.put("committed", "false");
Map<String, Object> metricsJson = console.doCallJson(options);
// Serialize metricsJson to JSON string for API or UI usage

Mermaid Class Diagram

classDiagram
    class KafkaDevConsole {
        <<extends AbstractDevConsole>>
        - static final Logger LOG
        - static final long COMMITTED_TIMEOUT
        - static final String COMMITTED
        + KafkaDevConsole()
        + String doCallText(Map<String,Object> options)
        + Map<String,Object> doCallJson(Map<String,Object> options)
        - static List<KafkaTopicPosition> fetchCommitOffsets(KafkaConsumer kc, DevConsoleMetricsCollector collector)
    }

    KafkaDevConsole --|> AbstractDevConsole

Summary

`KafkaDevConsole.java` is a critical observability tool within Apache Camel's Kafka component, providing deep visibility into Kafka consumer internals. It aids developers and operators with detailed thread-level metrics, error diagnostics, and offset commit information, supporting robust monitoring and troubleshooting workflows. Its design leverages Camel's dev console framework, integrating cleanly into the existing ecosystem and offering flexible output formats for diverse consumption scenarios.