KafkaConsumerAuthIT.java


Overview

`KafkaConsumerAuthIT.java` is an integration test class designed to validate the authentication and message consumption capabilities of the Apache Camel Kafka component when interacting with a Kafka broker secured using JAAS and SASL (PLAIN) authentication. It leverages a local Kafka container (`ContainerLocalAuthKafkaService`) configured with SASL/JAAS security to ensure that Camel can successfully produce and consume messages in a secure Kafka environment.

The test verifies that:

The class uses JUnit 5 for test lifecycle management, Camel testing support for route and context management, and Kafka clients for producing test data.


Detailed Description

Package

package org.apache.camel.component.kafka.integration;

This class resides in the integration tests package of the Camel Kafka component.


Class: KafkaConsumerAuthIT

This is the main test class annotated with JUnit 5 and Camel test infrastructure annotations to enable integration testing with an authenticated Kafka instance.

Annotations:

Constants:

Static Fields:

Instance Fields:


Lifecycle Methods

@BeforeEach void before()

@BeforeEach void setKafkaAdminClient()

@AfterEach void after()


Route Configuration

void createRouteBuilder(CamelContext context)

RouteBuilder createRouteBuilder()

Returns a Camel `RouteBuilder` that:


Tests

@Test void kafkaMessageIsConsumedByCamel()


Helper Methods

private void populateKafkaTopic(String propagatedHeaderKey, byte[] propagatedHeaderValue)


Important Implementation Details


Interactions with Other System Components


Usage Example

This class is primarily used as an integration test and is not intended for direct use in application code. However, it serves as an example of how to:


Mermaid Class Diagram

classDiagram
    class KafkaConsumerAuthIT {
        +static final String TOPIC
        +static ContainerLocalAuthKafkaService service
        +static CamelContextExtension contextExtension
        +static AdminClient kafkaAdminClient
        -org.apache.kafka.clients.producer.KafkaProducer<String,String> producer
        +void before()
        +void setKafkaAdminClient()
        +void after()
        +void createRouteBuilder(CamelContext)
        +RouteBuilder createRouteBuilder()
        +void kafkaMessageIsConsumedByCamel()
        -void populateKafkaTopic(String, byte[])
    }

Summary

`KafkaConsumerAuthIT.java` is a robust integration test validating Apache Camel Kafka component's functionality with SASL/JAAS secured Kafka clusters. It sets up a secured Kafka environment, configures Camel routes with proper authentication, sends test messages, and verifies their consumption and header propagation. This test ensures that the Kafka component works seamlessly with authenticated Kafka brokers in real-world scenarios.